From 5ffd3e17492c174ab5065132be864e939883d13e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20H=C3=BCgel?= Date: Sun, 19 Nov 2023 15:00:59 +0100 Subject: [PATCH] moved handler to a task and exclude containers from CI tests --- roles/update/handlers/main.yml | 6 ------ roles/update/tasks/system.yml | 29 +++++++++++++++++------------ 2 files changed, 17 insertions(+), 18 deletions(-) delete mode 100644 roles/update/handlers/main.yml diff --git a/roles/update/handlers/main.yml b/roles/update/handlers/main.yml deleted file mode 100644 index 6fdc6479e..000000000 --- a/roles/update/handlers/main.yml +++ /dev/null @@ -1,6 +0,0 @@ ---- -- name: Rebooting host - ansible.builtin.reboot: - reboot_timeout: 600 - test_command: uptime - listen: "reboot host" diff --git a/roles/update/tasks/system.yml b/roles/update/tasks/system.yml index bb490c224..a942306f1 100644 --- a/roles/update/tasks/system.yml +++ b/roles/update/tasks/system.yml @@ -34,21 +34,26 @@ - name: Check if a reboot is required ansible.builtin.stat: path: /var/run/reboot-required - get_md5: false - register: reboot_required - changed_when: reboot_required.stat.exists - when: ansible_os_family == "Debian" - notify: "reboot host" + register: reboot_required_debian + changed_when: false + when: + - ansible_os_family == "Debian" + - ansible_virtualization_type not in ['container', 'docker', 'lxc', 'podman'] # exclude for containers to prevent test failures in CI. - name: Check if a reboot is required ansible.builtin.command: needs-restarting -r - register: reboot_required - ignore_errors: true + register: reboot_required_rhel failed_when: false - changed_when: reboot_required.rc != 0 - when: ansible_os_family == "RedHat" - notify: "reboot host" + changed_when: false + when: + - ansible_os_family == "RedHat" + - ansible_virtualization_type not in ['container', 'docker', 'lxc', 'podman'] # exclude for containers to prevent test failures in CI. -- name: Make sure handlers are flushed immediately - ansible.builtin.meta: flush_handlers +- name: Rebooting host + ansible.builtin.reboot: + msg: "Reboot initiated by Ansible due to required system updates" + reboot_timeout: 1800 # 30 minutes + test_command: uptime + when: (reboot_required_debian.stat.exists is defined and reboot_required_debian.stat.exists) or + (reboot_required_rhel.rc is defined and reboot_required_rhel.rc != 0) ...