Utoljára aktív 1748021192

An Ansible playbook to update packages across a three-node Proxmox VE cluster

Revízió c6bd8eafb1a1df2ece558d6cecdb3f8267658098

proxmox_update_reboot.yml Eredeti
1---
2- hosts: proxmox
3 strategy: linear
4 vars:
5 ansible_command_timeout: 600 # Increased timeout for potential long-running updates and reboots
6 ansible_ssh_extra_args: '-o StrictHostKeyChecking=no'
7
8 pre_tasks:
9 - name: Enter node maintenance mode
10 command: pvecm node-maintenance
11 become: yes
12 register: maintenance_mode_result
13 changed_when: maintenance_mode_result.rc == 0
14
15 - name: Verify SSH connectivity
16 ping:
17 register: ssh_connection_check
18 ignore_errors: yes
19
20 - name: Fail if SSH connection is not working
21 fail:
22 msg: "Unable to establish SSH connection to the host"
23 when: ssh_connection_check.failed
24
25 tasks:
26 - name: Update apt cache
27 apt:
28 update_cache: yes
29 become: yes
30
31 - name: Upgrade all packages
32 apt:
33 upgrade: yes
34 autoremove: yes
35 autoclean: yes
36 become: yes
37
38 - name: Wait for 5 seconds before rebooting
39 wait_for:
40 timeout: 5
41
42- hosts: 172.16.30.41 # First host
43 vars:
44 ansible_ssh_extra_args: '-o StrictHostKeyChecking=no'
45
46 tasks:
47 - name: Reboot first host
48 reboot:
49 reboot_timeout: 300 # 5 minutes timeout for host to come back online
50 msg: "Rebooting for system updates"
51 become: yes
52
53 - name: Wait 30 seconds before next reboot
54 wait_for:
55 timeout: 30
56
57 - name: Exit node maintenance mode
58 command: pvecm node-resume
59 become: yes
60 register: maintenance_exit_result
61 changed_when: maintenance_exit_result.rc == 0
62
63- hosts: 172.16.30.42 # Second host
64 vars:
65 ansible_ssh_extra_args: '-o StrictHostKeyChecking=no'
66
67 tasks:
68 - name: Reboot second host
69 reboot:
70 reboot_timeout: 300
71 msg: "Rebooting for system updates"
72 become: yes
73
74 - name: Wait 30 seconds before next reboot
75 wait_for:
76 timeout: 30
77
78 - name: Exit node maintenance mode
79 command: pvecm node-resume
80 become: yes
81 register: maintenance_exit_result
82 changed_when: maintenance_exit_result.rc == 0
83
84- hosts: 172.16.30.43 # Third host
85 vars:
86 ansible_ssh_extra_args: '-o StrictHostKeyChecking=no'
87
88 tasks:
89 - name: Reboot third host
90 reboot:
91 reboot_timeout: 300
92 msg: "Rebooting for system updates"
93 become: yes
94
95 - name: Exit node maintenance mode
96 command: pvecm node-resume
97 become: yes
98 register: maintenance_exit_result
99 changed_when: maintenance_exit_result.rc == 0