From 9450ad26329b45ca120115a9fcb93eac6dfc5e10 Mon Sep 17 00:00:00 2001 From: Tobias Trabelsi Date: Fri, 7 Feb 2025 17:17:37 +0100 Subject: [PATCH] feat(Debian): add reboot handler if needed --- tasks/update-Debian.yml | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/tasks/update-Debian.yml b/tasks/update-Debian.yml index f0d892f..5b7dcef 100644 --- a/tasks/update-Debian.yml +++ b/tasks/update-Debian.yml @@ -1,22 +1,22 @@ --- - name: Update apt keys - become: yes + become: true command: apt-key update when: ansible_os_family == "Debian" or ansible_os_family == "OSMC" - name: Upgrade all packages to the latest version - become: yes + become: true apt: upgrade: dist - update_cache: yes + update_cache: true cache_valid_time: 3600 environment: PATH: "{{ ansible_env.PATH }}:/sbin:/usr/sbin" when: ansible_os_family == "Debian" or ansible_os_family == "OSMC" - name: Remove useless packages from the cache - become: yes + become: true become_method: sudo ignore_errors: true command: > @@ -26,7 +26,7 @@ when: ansible_os_family == "Debian" or ansible_os_family == "OSMC" - name: install packages - become: yes + become: true apt: name: "{{ package_list | list }}" state: present @@ -41,4 +41,29 @@ debug: msg: "Restart Required!!" ignore_errors: true - when: reboot_required_file.stat.exists == true \ No newline at end of file + when: reboot_required_file.stat.exists == true + +- name: "Reboot" + shell: 'sleep 2 && shutdown -r now' + become: true + async: 1 + poll: 0 + ignore_errors: true + when: reboot_required_file.stat.exists == true + +# This pause is mandatory, otherwise the existing control connection gets reused! +- name: "pause " + pause: + seconds: 30 + when: reboot_required_file.stat.exists == true + +- name: "wait till server comes back online" + local_action: shell ansible -u {{ ansible_user_id }} -m ping {{ inventory_hostname }} + register: result + until: result.rc == 0 + retries: 30 + delay: 15 + when: reboot_required_file.stat.exists == true + +- name: Re-gather facts + action: setup