-
Notifications
You must be signed in to change notification settings - Fork 1
/
destroy.yml
153 lines (122 loc) · 4.76 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
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
152
153
---
- hosts: localhost
connection: local
gather_facts: false
vars:
member_search_pattern: ".*{{ target }}$"
vars_prompt:
- name: ireallyreallymeanit
prompt: Are you sure you want to destroy the stack?
default: 'no'
private: no
pre_tasks:
- name: exit playbook, if user did not mean to destoy the stack
fail:
msg: >
"Exiting destroy playbook, stack was NOT purged.
To purge the cluster, either say 'yes' on the prompt or
or use `-e ireallyreallymeanit=yes` on the command line when
invoking the playbook"
when: ireallyreallymeanit != 'yes'
- name: authenticate to cloud
os_auth:
cloud: "{{ os_client_target }}"
tasks:
- name: list load-balancer pools
shell: neutron --os-cloud={{ os_client_target }} lbaas-pool-list -f json
register: pool_list
tags: lbaas
- set_fact:
pools: "{{ pool_list.stdout|from_json }}"
tags: lbaas
- set_fact:
pool: true
when: pools|length > 0 and pools|selectattr("name", "match", "load-balancer-pool")|list|length > 0
tags: lbaas
- block:
- name: list pool members
shell: neutron --os-cloud={{ os_client_target }} lbaas-member-list load-balancer-pool -f json
register: member_list
- set_fact:
members: "{{ member_list.stdout|from_json|selectattr('name', 'match', member_search_pattern)|list }}"
- name: remove pool members
shell: neutron --os-cloud={{ os_client_target }} lbaas-member-delete {{ item.name }} load-balancer-pool
with_items:
- "{{ members | default([]) }}"
when: members is defined
- name: delete pool
shell: neutron --os-cloud={{ os_client_target }} lbaas-pool-delete load-balancer-pool
when: pool is defined
tags: lbaas
- name: list load balancer listeners
shell: neutron --os-cloud={{ os_client_target }} lbaas-listener-list -f json
register: listener_instances
tags: lbaas
- set_fact:
listener_instance: "{{ listener_instances.stdout|from_json|selectattr('name', 'match', 'load-balancer-listener')|list }}"
when: listener_instances.stdout|from_json|length > 0
tags: lbaas
- name: delete load balancer listener
shell: neutron --os-cloud={{ os_client_target }} lbaas-listener-delete load-balancer-listener
when: listener_instance is defined
tags: lbaas
- name: list load balancer
shell: neutron --os-cloud={{ os_client_target }} lbaas-loadbalancer-list -f json
register: lbaas_instances
tags: lbaas
- set_fact:
lbaas_instance: "{{ lbaas_instances.stdout|from_json|selectattr('name', 'match', 'load-balancer')|list }}"
when: lbaas_instances.stdout|from_json|length > 0
tags: lbaas
- name: get load balancer facts
shell: neutron --os-cloud={{ os_client_target }} lbaas-loadbalancer-show load-balancer -f json
register: load_balancer_facts
when: lbaas_instance is defined
- set_fact:
lbaas_instance_detail: "{{ load_balancer_facts.stdout|from_json }}"
when: lbaas_instance is defined
- name: check for floating ip associated to load balancer
shell: neutron --os-cloud={{ os_client_target }} floatingip-list -f json
register: floatingip_list
when: lbaas_instance is defined
- set_fact:
floatingips: "{{ floatingip_list.stdout|from_json }}"
when: lbaas_instance is defined
- set_fact:
floatingip: "{{ floatingips|selectattr('port_id', 'match', lbaas_instance_detail.vip_port_id)|first }}"
when: lbaas_instance is defined and floatingips|length > 0 and floatingips|selectattr('port_id', 'match', lbaas_instance_detail.vip_port_id)|list|length > 0
- name: delete load balancer
shell: neutron --os-cloud={{ os_client_target }} lbaas-loadbalancer-delete load-balancer
when: lbaas_instance is defined
tags: lbaas
- name: disassociate floating ip from load balancer
shell: neutron --os-cloud={{ os_client_target }} floatingip-delete {{ floatingip.id }}
register: floatingip_association
when: floatingip is defined
- name: delete servers
os_server:
name: "{{ item }}-{{ target }}"
delete_fip: yes
state: absent
cloud: "{{ os_client_target }}"
with_items:
- railsapp-1
- railsapp-2
- postgresql
tags: servers
- name: delete router
os_router:
name: router
state: absent
cloud: "{{ os_client_target }}"
tags: network
- name: delete networks
os_network:
name: "{{ item }}"
state: absent
cloud: "{{ os_client_target }}"
with_items:
- database
- web
tags: network
...