-
Notifications
You must be signed in to change notification settings - Fork 5
/
remove_cdrom.yml
84 lines (73 loc) · 2.56 KB
/
remove_cdrom.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
---
- name: Destroy 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
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
# - debug:
# var: vm_info
- 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)
# - 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
# state_change_timeout: 200
# delegate_to: localhost
# - 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