42 lines
1.4 KiB
YAML

---
- name: Fetch VM status
uri:
url : "{{ __pve_endpoint }}/nodes/{{ item.vm_host | default(__pve_node) }}/qemu/\
{{ item.vmid }}/status/current"
method : GET
headers :
Content-type : "application/x-www-form-urlencoded"
Authorization : "{{ __pve_token }}"
vmid : "{{ item.vmid }}"
return_content : no
validate_certs : no
register : r_fetch_status
loop : "{{ lab_nodes }}"
loop_control :
label : "{{ item.name }}"
until : r_fetch_status.status == 200 and r_fetch_status.json.data.status is defined
retries : "{{ __api_retries }}"
delay : "{{ __api_polling }}"
- name: Shutdown VMs
uri:
url : "{{ __pve_endpoint }}/nodes/{{ item.item.vm_host | default(__pve_node) }}/qemu/\
{{ item.item.vmid }}/status/shutdown"
method : POST
headers :
Content-type : "application/x-www-form-urlencoded"
Authorization : "{{ __pve_token }}"
vmid : "{{ item.item.vmid }}"
return_content : no
validate_certs : no
register : r_start_vm
loop : "{{ r_fetch_status.results }}"
loop_control :
label : "{{ item.json.data.name }}"
when :
- item.json.data.status == 'running'|lower
...