Files
ansible/wake-and-update-ubuntu.yml
2024-09-12 09:27:25 +00:00

40 lines
1.0 KiB
YAML

---
- 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