From f1636e1eec5dbcfb9e41af87c30b33ba4590fce6 Mon Sep 17 00:00:00 2001 From: Lukas Greve Date: Fri, 24 Oct 2025 14:59:15 +0200 Subject: [PATCH] add new logic to detect whether rebooting is necessary or not --- update.yml | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/update.yml b/update.yml index 7e974f7..66088ff 100644 --- a/update.yml +++ b/update.yml @@ -8,10 +8,30 @@ yum: name: "*" state: latest - update_cache: yes + update_cache: yes - - name: Force reboot after updates (safe for Rocky Linux) + - name: Check if reboot required (RedHat/CentOS) + command: needs-restarting -r + register: needs_restarting_output + changed_when: false + ignore_errors: true + when: ansible_os_family == "RedHat" + + - name: Check if reboot required (Debian/Ubuntu) + stat: + path: /var/run/reboot-required + register: reboot_required_file + when: ansible_os_family != "RedHat" + + - name: Reboot if required (RedHat/CentOS) reboot: - msg: "System reboot after package updates" - post_reboot_delay: 10 - timeout: 300 + when: + - ansible_os_family == "RedHat" + - needs_restarting_output.rc == 1 + - needs_restarting_output is defined + + - name: Reboot if required (Debian/Ubuntu) + reboot: + when: + - ansible_os_family != "RedHat" + - reboot_required_file.stat.exists == true