blob: 2f05f099281e06893fec2e20ac32189ade346d1e (
plain)
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
|
- name: Terminate instance(s)
hosts: localhost
connection: local
gather_facts: no
vars_files:
- vars.yml
tasks:
- set_fact: cluster_group=tag_env_{{ cluster_id }}
- add_host:
name: "{{ item }}"
groups: oo_hosts_to_terminate
ansible_ssh_user: "{{ deployment_vars[deployment_type].ssh_user }}"
ansible_sudo: "{{ deployment_vars[deployment_type].sudo }}"
with_items: groups[cluster_group] | default([])
- hosts: oo_hosts_to_terminate
- hosts: localhost
connection: local
gather_facts: no
vars_files:
- vars.yml
tasks:
- name: Retrieve the floating IPs
shell: "neutron floatingip-list | awk '/{{ hostvars[item].ansible_default_ipv4.address }}/ {print $2}'"
with_items: groups['oo_hosts_to_terminate'] | default([])
register: floating_ips_to_delete
- name: Terminate instance(s)
nova_compute:
name: "{{ hostvars[item].os_name }}"
state: absent
with_items: groups['oo_hosts_to_terminate'] | default([])
- name: Delete floating IPs
command: "neutron floatingip-delete {{ item.stdout }}"
with_items: floating_ips_to_delete.results | default([])
- name: Destroy the network
command: "heat stack-delete {{ openstack_network_prefix }}-stack"
register: stack_delete_result
changed_when: stack_delete_result.rc == 0
failed_when: stack_delete_result.rc != 0 and 'could not be found' not in stack_delete_result.stdout
|