--- - hosts: all become: true tasks: - name: Update all servers (Debian/Ubuntu) apt: upgrade: dist update_cache: yes when: ansible_facts['os_family'] == "Debian" - name: Make sure Zypper is installed (Debian/Ubuntu) apt: name: zypper state: present when: ansible_facts['os_family'] == "Debian" - name: See if a reboot is needed for Ubuntu/Debian pct shell: "needs-restarting -r > /dev/null; echo $?" register: needsRestartingDebian changed_when: false when: ansible_facts['os_family'] == "Debian" - name: Debug needsRestartingDebian debug: msg: "Reboot needed: {{ needsRestartingDebian.stdout }}" when: ansible_facts['os_family'] == "Debian" - name: Reboot the server if necessary (Debian/Ubuntu) reboot: reboot_timeout: 600 when: ansible_facts['os_family'] == "Debian" and needsRestartingDebian.stdout == "1" - name: Update all servers (Fedora) dnf: name: "*" state: latest when: ansible_facts['os_family'] == "RedHat" - name: Make sure dnf-utils is installed dnf: name: dnf-utils state: present when: ansible_facts['os_family'] == "RedHat" - name: See if a reboot is needed (Fedora) shell: "needs-restarting -r > /dev/null; echo $?" register: needsRestartingFedora changed_when: false when: ansible_facts['os_family'] == "RedHat" - name: Debug needsRestartingFedora debug: msg: "Reboot needed: {{ needsRestartingFedora.stdout }}" when: ansible_facts['os_family'] == "RedHat" - name: Reboot the server if necessary (Fedora) reboot: reboot_timeout: 600 when: ansible_facts['os_family'] == "RedHat" and needsRestartingFedora.stdout == "1"