52 lines
1.5 KiB
YAML
52 lines
1.5 KiB
YAML
---
|
|||
|
|
|
||
|
|
- name: Managed Lab Maintenance
|
||
|
|
hosts: all_nodes
|
||
|
|
become: true
|
||
|
|
serial: 2 # Update 2 nodes at a time to reduce network/storage strain
|
||
|
|
|
||
|
|
tasks:
|
||
|
|
- name: 1. Update all packages via Nala
|
||
|
|
ansible.builtin.apt:
|
||
|
|
update_cache: yes
|
||
|
|
upgrade: dist
|
||
|
|
autoremove: yes
|
||
|
|
register: apt_res
|
||
|
|
|
||
|
|
- name: 2. Check if a reboot is required
|
||
|
|
ansible.builtin.stat:
|
||
|
|
path: /var/run/reboot-required
|
||
|
|
register: reboot_required_file
|
||
|
|
|
||
|
|
- name: 3. Conditional Reboot (Skip Physical Hosts for now)
|
||
|
|
when:
|
||
|
|
- reboot_required_file.stat.exists
|
||
|
|
- inventory_hostname not in groups['physical_iron'] # Handle physical hosts in a separate play
|
||
|
|
ansible.builtin.reboot:
|
||
|
|
msg: "Rebooting {{ inventory_hostname }} after updates"
|
||
|
|
reboot_timeout: 600
|
||
|
|
|
||
|
|
- name: Final Tier - Proxmox Host Maintenance
|
||
|
|
hosts: physical_iron
|
||
|
|
become: true
|
||
|
|
serial: 1 # Reboot physical hosts sequentially to avoid complete cluster downtime
|
||
|
|
|
||
|
|
tasks:
|
||
|
|
- name: Check if Host needs reboot
|
||
|
|
ansible.builtin.stat:
|
||
|
|
path: /var/run/reboot-required
|
||
|
|
register: host_reboot
|
||
|
|
|
||
|
|
- name: Proxmox Host Reboot Block
|
||
|
|
when: host_reboot.stat.exists
|
||
|
|
block:
|
||
|
|
- name: Graceful shutdown of all VMs/LXCs
|
||
|
|
ansible.builtin.shell: pvesh create /nodes/localhost/stopall
|
||
|
|
failed_when: false
|
||
|
|
|
||
|
|
- name: Reboot the Host
|
||
|
|
ansible.builtin.reboot:
|
||
|
|
msg: "Host maintenance reboot"
|
||
|
|
reboot_timeout: 900
|
||
|
|
|