-
Notifications
You must be signed in to change notification settings - Fork 1
/
delete.yml
executable file
·159 lines (124 loc) · 3.77 KB
/
delete.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
154
155
156
157
158
#!/usr/bin/env ansible-playbook
---
- name: Clean up Openstack after demo population
hosts: localhost
vars:
os_auth_url: "{{ lookup('env','OS_AUTH_URL') }}"
os_region: "regionOne"
oc_cloud_name: "{{ lookup('env','OS_CLOUDNAME') }}"
os_project_name: "admin"
os_username: "{{ lookup('env','OS_USERNAME') }}"
os_password: "{{ lookup('env','OS_PASSWORD') }}"
ssh_public_key: /home/stack/.ssh/id_rsa.pub
vars_files:
- vars/vars.yml
tasks:
# Set up an auth dir for shade
- file: path=~/.config/openstack/ state=directory mode=0755
- name: insert cerdentials into shade config
blockinfile:
create: yes
dest: ~/.config/openstack/clouds.yml
block: |
clouds:
overcloud:
auth:
auth_url: "{{ os_auth_url }}"
username: "{{ os_username }}"
password: "{{ os_password }}"
project_name: admin
# If you have sourced an OpenStack RC file, connecting to the
# Cloud is as simple as running the os_auth module with no additional
# parameters.
- name: Connect to the Cloud
os_auth:
# If you have not sourced an OpenStack RC file, you will need to pass a few
# mandatory authentication attributes, as demonstrated below.
#- name: Connect to the Catalyst Cloud
# os_auth:
auth:
auth_url: "{{ os_auth_url }}"
username: "{{ os_username }}"
password: "{{ os_password }}"
project_name: "{{ os_project_name }}"
# Instances tasks
- name: Detach volumes from instance
os_server_volume:
state: absent
cloud: overcloud
server: "{{ item.name }}"
volume: "{{ item.volume }}"
with_items: "{{ instances }}"
- name: Delete the instances
os_server:
state: absent
name: "{{ item.name }}"
with_items: "{{ instances }}"
- name: remove imported an SSH keypairs
os_keypair:
state: absent
name: "{{ item.name }}"
with_items: "{{ keypairs }}"
# Images tasks
- name: Delete uploaded images
os_image:
cloud: overcloud
name: "{{ item.name }}"
state: absent
with_items: "{{ images }}"
# # Object resources
- name: Remove objects
os_object:
cloud: overcloud
state: absent
name: "{{ item.name }}"
container: "{{ item.container }}"
with_items: "{{ objects }}"
- name: Delete containers
os_object:
cloud: overcloud
state: absent
container: "{{ item.name }}"
with_items: "{{ containers }}"
# Volumes tasks
- name: Delete volumes
os_volume:
state: absent
cloud: overcloud
display_name: "{{ item.name }}"
with_items: "{{ volumes }}"
# Network tasks
- name: Delete routers
os_router:
state: absent
name: "{{ item.name }}"
ignore_errors: yes
with_items: "{{ routers }}"
- name: Delete subnets
os_subnet:
state: absent
name: "{{ item.name }}"
network_name: "{{ item.network_name }}"
with_items: "{{ subnets }}"
- name: Delete networks
os_network:
state: absent
name: "{{ item.name }}"
with_items: "{{ networks }}"
- name: Delete security groups
os_security_group:
state: absent
name: "{{ item.name }}"
with_items: "{{ security_groups }}"
# ---Keystone level resources---
- name: Delete Users
os_user:
cloud: overcloud
state: absent
name: "{{ item.name }}"
with_items: "{{ users }}"
- name: Delete tenants/projects
os_project:
state: absent
name: "{{ item.name }}"
with_items: "{{ projects }}"