Files
ansible/wake-and-update-ubuntu.yml
2024-07-11 00:21:01 +02:00

40 lines
5.9 KiB
YAML

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