ya1
This commit is contained in:
39
wake-and-update-ubuntu.yml
Normal file
39
wake-and-update-ubuntu.yml
Normal file
@@ -0,0 +1,39 @@
|
||||
---
|
||||
- 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
|
||||
Reference in New Issue
Block a user