-
Notifications
You must be signed in to change notification settings - Fork 3
/
deployer_cleanup.yml
151 lines (140 loc) · 3.94 KB
/
deployer_cleanup.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
---
# Deletes all VMs created from the master_deployer playbook
# Only if the VM name in Nutanix matches against any vm_defs.vm_name definition (see group_vars/all.yml)
# Delete tasks are tagged to never run unless the approriate tag is specified.
# Ex (Delete all Tower and OCP machines) :
# ansible-playbook -i inventories/dell_lab cleanup_deployer.yml --tags "tower,ocp"
- name: Delete Nutanix Instances
hosts: localhost
gather_facts: false
tasks:
- name: Auth to the cluster
uri:
url: "{{ api_url_v3 }}/clusters/list"
body:
kind: cluster
sort_order: ASCENDING
offset: 0
length: 10
sort_attribute: ''
method: POST
validate_certs: no
force_basic_auth: yes
body_format: json
user: "{{ prism_user }}"
password: "{{ prism_password }}"
status_code: 200
return_content: yes
register: login
ignore_errors: yes
tags:
- always
- debug:
var: login.set_cookie
when: global_debug
- set_fact:
session_cookie: "{{ login.set_cookie }}"
tags:
- always
- name: Get VMS list
uri:
url: "{{ api_url_v3 }}/vms/list"
body:
kind: vm
sort_order: ASCENDING
offset: 0
length: 1000
sort_attribute: ''
method: POST
validate_certs: no
body_format: json
status_code: 200
headers:
Cookie: "{{ session_cookie }}"
register: vms_result
ignore_errors: yes
tags:
- always
- name: Stash the VM UUIDs
set_fact:
vm_uuids: "{{ vm_uuids|default([]) + [{'name': item.spec.name, 'uuid': item.metadata.uuid}] }}"
with_items: "{{ vms_result.json.entities }}"
tags:
- always
- debug:
var: vm_uuids
- name: Delete Repo VMs
uri:
url: "{{ api_url_v3 }}/vms/{{ item.uuid }}"
method: DELETE
validate_certs: no
status_code: 202
headers:
Cookie: "{{ session_cookie }}"
register: vm_delete_result
ignore_errors: yes
when: "item.name in vm_defs_repo|map(attribute='vm_name')|list"
loop: "{{ vm_uuids }}"
tags:
- never
- repo
- name: Delete Tower VMs
uri:
url: "{{ api_url_v3 }}/vms/{{ item.uuid }}"
method: DELETE
validate_certs: no
status_code: 202
headers:
Cookie: "{{ session_cookie }}"
register: vm_delete_result
ignore_errors: yes
when: "item.name in vm_defs_tower|map(attribute='vm_name')|list"
loop: "{{ vm_uuids }}"
tags:
- never
- tower
- name: Delete OCP VMs
uri:
url: "{{ api_url_v3 }}/vms/{{ item.uuid }}"
method: DELETE
validate_certs: no
status_code: 202
headers:
Cookie: "{{ session_cookie }}"
register: vm_delete_result
ignore_errors: yes
when: "item.name in vm_defs_ocp|map(attribute='vm_name')|list"
loop: "{{ vm_uuids }}"
tags:
- never
- ocp
- name: Delete Load Balancer VMs
uri:
url: "{{ api_url_v3 }}/vms/{{ item.uuid }}"
method: DELETE
validate_certs: no
status_code: 202
headers:
Cookie: "{{ session_cookie }}"
register: vm_delete_result
ignore_errors: yes
when: "item.name in vm_defs_lbs|map(attribute='vm_name')|list"
loop: "{{ vm_uuids }}"
tags:
- never
- lbs
- name: Delete CNS VMs
uri:
url: "{{ api_url_v3 }}/vms/{{ item.uuid }}"
method: DELETE
validate_certs: no
status_code: 202
headers:
Cookie: "{{ session_cookie }}"
register: vm_delete_result
ignore_errors: yes
when: "item.name in vm_defs_cns|map(attribute='vm_name')|list"
loop: "{{ vm_uuids }}"
tags:
- never
- cns