-
Notifications
You must be signed in to change notification settings - Fork 3
/
delete_vms.yml
42 lines (38 loc) · 1.33 KB
/
delete_vms.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
---
- hosts: vmware-vm
gather_facts: no
connection: local
tasks:
- name: PowerOff VM
vmware_guest:
validate_certs: False
hostname: "{{ vm_vsphere_host }}"
username: "{{ vm_vsphere_user }}"
password: "{{ vm_vsphere_password }}"
datacenter: "{{ vm_vsphere_datacenter }}"
folder: "{{ vm_vsphere_datacenter }}/vm/{{ vm_folder }}"
name: "{{ inventory_hostname }}"
state: poweredoff
- name: Wait till all the VMs are powered off
vmware_guest_facts:
validate_certs: False
hostname: "{{ vm_vsphere_host }}"
username: "{{ vm_vsphere_user }}"
password: "{{ vm_vsphere_password }}"
datacenter: "{{ vm_vsphere_datacenter }}"
folder: "{{ vm_vsphere_datacenter }}/vm/{{ vm_folder }}"
name: "{{ inventory_hostname }}"
register: facts
until: facts.instance.hw_power_status == "poweredOff"
retries: 10
delay: 5
- name: Delete VM
vmware_guest:
validate_certs: False
hostname: "{{ vm_vsphere_host }}"
username: "{{ vm_vsphere_user }}"
password: "{{ vm_vsphere_password }}"
datacenter: "{{ vm_vsphere_datacenter }}"
folder: "{{ vm_vsphere_datacenter }}/vm/{{ vm_folder }}"
name: "{{ inventory_hostname }}"
state: absent