4
4
block :
5
5
6
6
- name : Extract Node and VM ID for VM {{ item.vm_name }}
7
- set_fact :
7
+ ansible.builtin. set_fact :
8
8
vm_id : " {{ proxmox_cluster_information.json.data | selectattr('name', 'equalto', item.vm_name) | map(attribute='vmid') | first }}"
9
9
vm_node : " {{ proxmox_cluster_information.json.data | selectattr('name', 'equalto', item.vm_name) | map(attribute='node') | first }}"
10
10
vm_type : " {{ proxmox_cluster_information.json.data | selectattr('name', 'equalto', item.vm_name) | map(attribute='type') | first }}"
11
-
11
+
12
12
- name : Get VM Status
13
- uri :
13
+ ansible.builtin. uri :
14
14
method : GET
15
- validate_certs : no
15
+ validate_certs : false
16
16
url : " https://{{ proxmox_api_host }}:{{ proxmox_api_port }}/api2/json/nodes/{{ vm_node }}/{{ vm_type }}/{{ vm_id }}/status/current"
17
17
headers : " {{ proxmox_api_cookie }}"
18
18
register : vm_status
19
19
20
20
- name : Start qemu VM {{ item.vm_name }}
21
- uri :
21
+ ansible.builtin. uri :
22
22
method : POST
23
- validate_certs : no
23
+ validate_certs : false
24
24
url : " https://{{ proxmox_api_host }}:{{ proxmox_api_port }}/api2/json/nodes/{{ vm_node }}/{{ vm_type }}/{{ vm_id }}/status/start"
25
25
headers : " {{ proxmox_api_cookie }}"
26
26
body_format : form-urlencoded
29
29
when : vm_status.json.data.status == 'stopped' and vm_type == 'qemu'
30
30
31
31
- name : Start lxc VM {{ item.vm_name }}
32
- uri :
32
+ ansible.builtin. uri :
33
33
method : POST
34
- validate_certs : no
34
+ validate_certs : false
35
35
url : " https://{{ proxmox_api_host }}:{{ proxmox_api_port }}/api2/json/nodes/{{ vm_node }}/{{ vm_type }}/{{ vm_id }}/status/start"
36
36
headers : " {{ proxmox_api_cookie }}"
37
37
body_format : form-urlencoded
38
38
when : vm_status.json.data.status == 'stopped' and vm_type == 'lxc'
39
39
40
40
- name : Waiting for the VM to boot up
41
- pause :
41
+ ansible.builtin. pause :
42
42
seconds : " {{ boot_time }}"
43
43
when : vm_status.json.data.status == 'stopped'
44
-
44
+
45
45
- name : Gather VM Facts
46
- gather_facts :
46
+ ansible.builtin. gather_facts :
47
47
register : vm_facts
48
48
delegate_to : " {{ item.vm_name }}"
49
49
50
50
- name : Take a VM Snapshot of qemu VM {{ item.vm_name }}
51
- uri :
51
+ ansible.builtin. uri :
52
52
method : POST
53
- validate_certs : no
53
+ validate_certs : false
54
54
url : " https://{{ proxmox_api_host }}:{{ proxmox_api_port }}/api2/json/nodes/{{ vm_node }}/{{ vm_type }}/{{ vm_id }}/snapshot"
55
55
headers : " {{ proxmox_api_cookie }}"
56
56
body_format : form-urlencoded
59
59
description : " Snapshot taken by Update Automation"
60
60
vmstate : 1
61
61
when : (item.snapshot|default(false)) and vm_type == 'qemu'
62
-
62
+
63
63
- name : Take a VM Snapshot of lxc VM {{ item.vm_name }}
64
- uri :
64
+ ansible.builtin. uri :
65
65
method : POST
66
- validate_certs : no
66
+ validate_certs : false
67
67
url : " https://{{ proxmox_api_host }}:{{ proxmox_api_port }}/api2/json/nodes/{{ vm_node }}/{{ vm_type }}/{{ vm_id }}/snapshot"
68
68
headers : " {{ proxmox_api_cookie }}"
69
69
body_format : form-urlencoded
73
73
when : (item.snapshot|default(false)) and vm_type == 'lxc'
74
74
75
75
- name : Waiting for the VM to finish Snapshot
76
- pause :
76
+ ansible.builtin. pause :
77
77
seconds : " {{ boot_time }}"
78
78
when : (item.snapshot|default(false))
79
-
79
+
80
80
- name : Update VM {{ item.vm_name }} with apt
81
- apt :
82
- force_apt_get : yes
81
+ ansible.builtin. apt :
82
+ force_apt_get : true
83
83
name : " *"
84
84
state : latest
85
- update_cache : yes
85
+ update_cache : true
86
86
become : true
87
87
delegate_to : " {{ item.vm_name }}"
88
88
when : vm_facts.ansible_facts.ansible_os_family == 'Debian'
89
-
89
+
90
90
- name : Update VM {{ item.vm_name }} with yum
91
- yum :
91
+ ansible.builtin. yum :
92
92
name : " *"
93
93
state : latest
94
- update_cache : yes
94
+ update_cache : true
95
95
lock_timeout : 120
96
96
become : true
97
97
delegate_to : " {{ item.vm_name }}"
98
98
when : vm_facts.ansible_facts.ansible_os_family == 'RedHat'
99
99
100
100
- name : Install Prerequisite Packages for OpenSuse / SLES
101
- package :
101
+ ansible.builtin. package :
102
102
name :
103
103
- python-xml
104
104
- zypper
109
109
when : vm_facts.ansible_facts.ansible_os_family == 'Suse'
110
110
111
111
- name : Update VM {{ item.vm_name }} with zypper
112
- zypper :
112
+ community.general. zypper :
113
113
name : " *"
114
114
state : latest
115
- update_cache : yes
115
+ update_cache : true
116
116
type : patch
117
117
become : true
118
118
delegate_to : " {{ item.vm_name }}"
119
119
when : vm_facts.ansible_facts.ansible_os_family == 'Suse'
120
-
120
+
121
121
- name : Shutdown VM {{ item.vm_name }} when it was stopped before patching
122
- uri :
122
+ ansible.builtin. uri :
123
123
method : POST
124
- validate_certs : no
124
+ validate_certs : false
125
125
url : " https://{{ proxmox_api_host }}:{{ proxmox_api_port }}/api2/json/nodes/{{ vm_node }}/{{ vm_type }}/{{ vm_id }}/status/shutdown"
126
126
headers : " {{ proxmox_api_cookie }}"
127
127
body_format : form-urlencoded
130
130
when : vm_status.json.data.status == 'stopped'
131
131
132
132
- name : Check if a Reboot is required for Debian / Ubuntu
133
- stat :
133
+ ansible.builtin. stat :
134
134
path : /var/run/reboot-required
135
135
become : true
136
136
register : reboot_required
137
137
delegate_to : " {{ item.vm_name }}"
138
- when : (not vm_status.json.data.status == 'stopped') and (item.reboot_if_required|default(false)) and (vm_facts.ansible_facts.ansible_os_family == 'Debian')
138
+ when :
139
+ - (not vm_status.json.data.status == 'stopped')
140
+ - (item.reboot_if_required|default(false))
141
+ - (vm_facts.ansible_facts.ansible_os_family == 'Debian')
139
142
140
143
- name : Reboot VM after Update
141
- reboot :
144
+ ansible.builtin. reboot :
142
145
become : true
143
146
delegate_to : " {{ item.vm_name }}"
144
147
when : (reboot_required.stat.exists|default(false))
145
148
146
149
rescue :
147
- - debug :
148
- msg : " There was an Error during Patch Installation on {{ item.vm_name }}. Maybe you misspelled the VM Name. Be aware, that Proxmox VM Names are case sensitive!"
150
+ - ansible.builtin.debug :
151
+ msg :
152
+ - " There was an Error during Patch Installation on {{ item.vm_name }}."
153
+ - " Maybe you misspelled the VM Name. Be aware, that Proxmox VM Names are case sensitive!"
0 commit comments