proxmox_update_reboot.yml
· 2.4 KiB · YAML
Неформатований
---
- hosts: proxmox
strategy: linear
vars:
ansible_command_timeout: 600 # Increased timeout for potential long-running updates and reboots
ansible_ssh_extra_args: '-o StrictHostKeyChecking=no'
pre_tasks:
- name: Enter node maintenance mode
command: pvecm node-maintenance
become: yes
register: maintenance_mode_result
changed_when: maintenance_mode_result.rc == 0
- name: Verify SSH connectivity
ping:
register: ssh_connection_check
ignore_errors: yes
- name: Fail if SSH connection is not working
fail:
msg: "Unable to establish SSH connection to the host"
when: ssh_connection_check.failed
tasks:
- name: Update apt cache
apt:
update_cache: yes
become: yes
- name: Upgrade all packages
apt:
upgrade: yes
autoremove: yes
autoclean: yes
become: yes
- name: Wait for 5 seconds before rebooting
wait_for:
timeout: 5
- hosts: 172.16.30.41 # First host
vars:
ansible_ssh_extra_args: '-o StrictHostKeyChecking=no'
tasks:
- name: Reboot first host
reboot:
reboot_timeout: 300 # 5 minutes timeout for host to come back online
msg: "Rebooting for system updates"
become: yes
- name: Wait 30 seconds before next reboot
wait_for:
timeout: 30
- name: Exit node maintenance mode
command: pvecm node-resume
become: yes
register: maintenance_exit_result
changed_when: maintenance_exit_result.rc == 0
- hosts: 172.16.30.42 # Second host
vars:
ansible_ssh_extra_args: '-o StrictHostKeyChecking=no'
tasks:
- name: Reboot second host
reboot:
reboot_timeout: 300
msg: "Rebooting for system updates"
become: yes
- name: Wait 30 seconds before next reboot
wait_for:
timeout: 30
- name: Exit node maintenance mode
command: pvecm node-resume
become: yes
register: maintenance_exit_result
changed_when: maintenance_exit_result.rc == 0
- hosts: 172.16.30.43 # Third host
vars:
ansible_ssh_extra_args: '-o StrictHostKeyChecking=no'
tasks:
- name: Reboot third host
reboot:
reboot_timeout: 300
msg: "Rebooting for system updates"
become: yes
- name: Exit node maintenance mode
command: pvecm node-resume
become: yes
register: maintenance_exit_result
changed_when: maintenance_exit_result.rc == 0
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 |