-
Notifications
You must be signed in to change notification settings - Fork 5
/
destroy.yml
58 lines (50 loc) · 1.71 KB
/
destroy.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
---
- name: Destroy all OCP vms
hosts: ocp
become: yes
gather_facts: no
vars_files:
- vault.yml
- vars/rhel_vmware.yml
tasks:
- name: "List of all ocp vms in {{vm_folder}}"
debug:
var: groups['ocp'] | list | sort
delegate_to: localhost
run_once: true
- pause:
prompt: "This will destory all OCP vms in {{vm_folder}}. (ctrl+c to abort. Any key to continue)?"
- name: Get vm info
vmware_vm_info:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: "{{ not vcenter_insecure_ssl }}"
folder: "{{ vm_folder }}"
vm_type: vm
register: vm_info
delegate_to: localhost
- name: Set json query fact
set_fact:
query: "[?guest_name=='{{ inventory_hostname }}.{{ dns_domain }}']"
- block:
- name: Power off vm
vmware_guest_powerstate:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: "{{ not vcenter_insecure_ssl }}"
folder: "{{ vm_folder }}"
name: "{{ inventory_hostname }}.{{ dns_domain }}"
state: powered-off
- name: Destroy vm
vmware_guest:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: "{{ not vcenter_insecure_ssl }}"
folder: "{{ vm_folder }}"
name: "{{ inventory_hostname + '.' + dns_domain }}"
state: absent
delegate_to: localhost
when: vm_info.virtual_machines | json_query(query)