-
Notifications
You must be signed in to change notification settings - Fork 1
/
awx-proxmox-remove-vm.yml
61 lines (54 loc) · 1.8 KB
/
awx-proxmox-remove-vm.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
- name: "Proxmox: VM Removal"
connection: local
hosts: all
gather_facts: False
vars:
collected_proxmox_vms: {}
tasks:
- name: Include Proxmox common discovery
include_tasks: "ansible-tasks/collect-proxmox-vms.yml"
- name: Stop specified VM
community.general.proxmox_kvm:
#node: "{{ proxmox_env_info.node }}"
api_user: "{{ proxmox_env_info.api_user }}"
api_token_id: "{{ proxmox_env_info.api_token_id }}"
api_token_secret: "{{ proxmox_env_info.api_token_secret }}"
api_host: "{{ proxmox_env_info.api_host }}"
name: "{{ vm_config['name'] }}"
state: stopped
force: true
when: vm_config['name'] in collected_proxmox_vms
register: stop_vm_job
async: 180
poll: 0
- name: Wait for VM stop process to finish
async_status:
jid: "{{ stop_vm_job.ansible_job_id }}"
when: vm_config['name'] in collected_proxmox_vms
register: _sjobs_alias_vc_0
until: _sjobs_alias_vc_0.finished
retries: 100
delay: 10
- name: "Proxmox: Remove specified VM"
community.general.proxmox_kvm:
node: "{{ proxmox_env_info.node }}"
api_user: "{{ proxmox_env_info.api_user }}"
api_token_id: "{{ proxmox_env_info.api_token_id }}"
api_token_secret: "{{ proxmox_env_info.api_token_secret }}"
api_host: "{{ proxmox_env_info.api_host }}"
name: "{{ vm_config['name'] }}"
#vmid: "{{ nb_remove_vms[item] }}"
state: absent
force: true
when: vm_config['name'] in collected_proxmox_vms
register: remove_vms_job
async: 180
poll: 0
- name: "Proxmox: Wait for VM removal"
async_status:
jid: "{{ remove_vms_job.ansible_job_id }}"
when: vm_config['name'] in collected_proxmox_vms
register: _rjobs_alias_vc_0
until: _rjobs_alias_vc_0.finished
retries: 100
delay: 5