--- - name: Update and upgrade Ansible host hosts: AnsibleHost become: true gather_facts: true tasks: - name: Update and upgrade apt packages apt: update_cache: yes upgrade: safe when: ansible_os_family == "Debian" - name: Check if reboot is required ansible.builtin.stat: path: /var/run/reboot-required get_checksum: no register: reboot_required_file when: ansible_os_family == "Debian" - name: Reboot if required ansible.builtin.reboot: when: reboot_required_file is defined and reboot_required_file.stat.exists