Skip to content

Commit d71b2ea

Browse files
committed
fixed linting errors and specified fqdn module names
1 parent 26ba29a commit d71b2ea

File tree

2 files changed

+48
-43
lines changed

2 files changed

+48
-43
lines changed

patch_vm.yml

+40-35
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@
44
block:
55

66
- name: Extract Node and VM ID for VM {{ item.vm_name }}
7-
set_fact:
7+
ansible.builtin.set_fact:
88
vm_id: "{{ proxmox_cluster_information.json.data | selectattr('name', 'equalto', item.vm_name) | map(attribute='vmid') | first }}"
99
vm_node: "{{ proxmox_cluster_information.json.data | selectattr('name', 'equalto', item.vm_name) | map(attribute='node') | first }}"
1010
vm_type: "{{ proxmox_cluster_information.json.data | selectattr('name', 'equalto', item.vm_name) | map(attribute='type') | first }}"
11-
11+
1212
- name: Get VM Status
13-
uri:
13+
ansible.builtin.uri:
1414
method: GET
15-
validate_certs: no
15+
validate_certs: false
1616
url: "https://{{ proxmox_api_host }}:{{ proxmox_api_port }}/api2/json/nodes/{{ vm_node }}/{{ vm_type }}/{{ vm_id }}/status/current"
1717
headers: "{{ proxmox_api_cookie }}"
1818
register: vm_status
1919

2020
- name: Start qemu VM {{ item.vm_name }}
21-
uri:
21+
ansible.builtin.uri:
2222
method: POST
23-
validate_certs: no
23+
validate_certs: false
2424
url: "https://{{ proxmox_api_host }}:{{ proxmox_api_port }}/api2/json/nodes/{{ vm_node }}/{{ vm_type }}/{{ vm_id }}/status/start"
2525
headers: "{{ proxmox_api_cookie }}"
2626
body_format: form-urlencoded
@@ -29,28 +29,28 @@
2929
when: vm_status.json.data.status == 'stopped' and vm_type == 'qemu'
3030

3131
- name: Start lxc VM {{ item.vm_name }}
32-
uri:
32+
ansible.builtin.uri:
3333
method: POST
34-
validate_certs: no
34+
validate_certs: false
3535
url: "https://{{ proxmox_api_host }}:{{ proxmox_api_port }}/api2/json/nodes/{{ vm_node }}/{{ vm_type }}/{{ vm_id }}/status/start"
3636
headers: "{{ proxmox_api_cookie }}"
3737
body_format: form-urlencoded
3838
when: vm_status.json.data.status == 'stopped' and vm_type == 'lxc'
3939

4040
- name: Waiting for the VM to boot up
41-
pause:
41+
ansible.builtin.pause:
4242
seconds: "{{ boot_time }}"
4343
when: vm_status.json.data.status == 'stopped'
44-
44+
4545
- name: Gather VM Facts
46-
gather_facts:
46+
ansible.builtin.gather_facts:
4747
register: vm_facts
4848
delegate_to: "{{ item.vm_name }}"
4949

5050
- name: Take a VM Snapshot of qemu VM {{ item.vm_name }}
51-
uri:
51+
ansible.builtin.uri:
5252
method: POST
53-
validate_certs: no
53+
validate_certs: false
5454
url: "https://{{ proxmox_api_host }}:{{ proxmox_api_port }}/api2/json/nodes/{{ vm_node }}/{{ vm_type }}/{{ vm_id }}/snapshot"
5555
headers: "{{ proxmox_api_cookie }}"
5656
body_format: form-urlencoded
@@ -59,11 +59,11 @@
5959
description: "Snapshot taken by Update Automation"
6060
vmstate: 1
6161
when: (item.snapshot|default(false)) and vm_type == 'qemu'
62-
62+
6363
- name: Take a VM Snapshot of lxc VM {{ item.vm_name }}
64-
uri:
64+
ansible.builtin.uri:
6565
method: POST
66-
validate_certs: no
66+
validate_certs: false
6767
url: "https://{{ proxmox_api_host }}:{{ proxmox_api_port }}/api2/json/nodes/{{ vm_node }}/{{ vm_type }}/{{ vm_id }}/snapshot"
6868
headers: "{{ proxmox_api_cookie }}"
6969
body_format: form-urlencoded
@@ -73,32 +73,32 @@
7373
when: (item.snapshot|default(false)) and vm_type == 'lxc'
7474

7575
- name: Waiting for the VM to finish Snapshot
76-
pause:
76+
ansible.builtin.pause:
7777
seconds: "{{ boot_time }}"
7878
when: (item.snapshot|default(false))
79-
79+
8080
- name: Update VM {{ item.vm_name }} with apt
81-
apt:
82-
force_apt_get: yes
81+
ansible.builtin.apt:
82+
force_apt_get: true
8383
name: "*"
8484
state: latest
85-
update_cache: yes
85+
update_cache: true
8686
become: true
8787
delegate_to: "{{ item.vm_name }}"
8888
when: vm_facts.ansible_facts.ansible_os_family == 'Debian'
89-
89+
9090
- name: Update VM {{ item.vm_name }} with yum
91-
yum:
91+
ansible.builtin.yum:
9292
name: "*"
9393
state: latest
94-
update_cache: yes
94+
update_cache: true
9595
lock_timeout: 120
9696
become: true
9797
delegate_to: "{{ item.vm_name }}"
9898
when: vm_facts.ansible_facts.ansible_os_family == 'RedHat'
9999

100100
- name: Install Prerequisite Packages for OpenSuse / SLES
101-
package:
101+
ansible.builtin.package:
102102
name:
103103
- python-xml
104104
- zypper
@@ -109,19 +109,19 @@
109109
when: vm_facts.ansible_facts.ansible_os_family == 'Suse'
110110

111111
- name: Update VM {{ item.vm_name }} with zypper
112-
zypper:
112+
community.general.zypper:
113113
name: "*"
114114
state: latest
115-
update_cache: yes
115+
update_cache: true
116116
type: patch
117117
become: true
118118
delegate_to: "{{ item.vm_name }}"
119119
when: vm_facts.ansible_facts.ansible_os_family == 'Suse'
120-
120+
121121
- name: Shutdown VM {{ item.vm_name }} when it was stopped before patching
122-
uri:
122+
ansible.builtin.uri:
123123
method: POST
124-
validate_certs: no
124+
validate_certs: false
125125
url: "https://{{ proxmox_api_host }}:{{ proxmox_api_port }}/api2/json/nodes/{{ vm_node }}/{{ vm_type }}/{{ vm_id }}/status/shutdown"
126126
headers: "{{ proxmox_api_cookie }}"
127127
body_format: form-urlencoded
@@ -130,19 +130,24 @@
130130
when: vm_status.json.data.status == 'stopped'
131131

132132
- name: Check if a Reboot is required for Debian / Ubuntu
133-
stat:
133+
ansible.builtin.stat:
134134
path: /var/run/reboot-required
135135
become: true
136136
register: reboot_required
137137
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')
139142

140143
- name: Reboot VM after Update
141-
reboot:
144+
ansible.builtin.reboot:
142145
become: true
143146
delegate_to: "{{ item.vm_name }}"
144147
when: (reboot_required.stat.exists|default(false))
145148

146149
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!"

update_proxmox_vm.yml

+8-8
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
tasks:
1919

2020
- name: Logon to Proxmox Server
21-
uri:
21+
ansible.builtin.uri:
2222
method: POST
23-
validate_certs: no
24-
return_content: yes
23+
validate_certs: false
24+
return_content: true
2525
url: "https://{{ proxmox_api_host }}:8006/api2/json/access/ticket"
2626
body_format: json
2727
body:
@@ -31,20 +31,20 @@
3131
become: false
3232

3333
- name: parse cookie data
34-
set_fact:
34+
ansible.builtin.set_fact:
3535
proxmox_api_cookie:
3636
Cookie: "PVEAuthCookie={{ proxmox_session.json.data.ticket }}"
3737
CSRFPreventionToken: "{{ proxmox_session.json.data.CSRFPreventionToken }}"
3838
no_log: true
3939

4040
- name: get information about all vms in the cluster
41-
uri:
41+
ansible.builtin.uri:
4242
method: GET
43-
validate_certs: no
43+
validate_certs: false
4444
url: "https://{{ proxmox_api_host }}:8006/api2/json/cluster/resources?type=vm"
4545
headers: "{{ proxmox_api_cookie }}"
4646
register: proxmox_cluster_information
4747

4848
- name: Patch VM
49-
include_tasks: patch_vm.yml
50-
loop: "{{ vm_list }}"
49+
ansible.builtin.include_tasks: patch_vm.yml
50+
loop: "{{ vm_list }}"

0 commit comments

Comments
 (0)