--- - name: Update and Shutdown Ubuntu Server hosts: ubuntu_server become: true gather_facts: false tasks: - name: Wake up the server using Wake-on-LAN local_action: module: community.general.wakeonlan mac: MAC_ADDRESS_HERE broadcast: BROADCAST_ADDRESS_HERE delegate_to: localhost - name: Wait for the server to come online ansible.builtin.wait_for: host: "{{ inventory_hostname }}" port: 22 state: started timeout: 300 - name: Update all packages to the latest version ansible.builtin.apt: update_cache: true upgrade: dist autoremove: true autoclean: true - name: Reboot the server ansible.builtin.reboot: - name: Check if updates were successful register: upgradable_packages changed_when: false failed_when: upgradable_packages.stdout != "" ansible.builtin.command: apt list --upgradable - name: Shut down the server ansible.builtin.command: shutdown now