-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleanup.yml
102 lines (92 loc) · 3.07 KB
/
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
---
- name: Add host to host list
hosts: localhost
gather_facts: no
any_errors_fatal: true
vars:
hypervisor: "{{ provision.host }}"
hypervisor_name: hypervisor
tasks:
- name: add hosts to host list
add_host:
name: "{{ hypervisor.name | default(hypervisor_name) }}"
groups: "{{ hypervisor.groups|default([hypervisor_name]) | join(',') }}"
ansible_user: "{{ hypervisor.user }}"
ansible_host: "{{ hypervisor.address }}"
ansible_ssh_private_key_file: "{{ hypervisor.key }}"
- name: Remove all VMs and networks that were created
hosts: hypervisor
gather_facts: yes
any_errors_fatal: true
vars:
# ignore virsh's default network
ignore_virsh_nets:
- default
tasks:
- name: check if installed package
command: "rpm -qa libvirt"
register: libvirt_status
# Don't cleanup if the libvirtd process is unavailable
- name: Cleanup libvirt artifacts
include_tasks: tasks/cleanup.yml
when: "(libvirt_status.stdout_lines | length != 0)"
- name: remove iptables rules created by infrared, by comment
# Can't use iptables module, because it can't delete by generic comment
vars:
iptables_comment_search: "Infrared"
shell: |
set -euo pipefail
for table in "-t nat" ""
do
iptables ${table} -S | awk '/{{ iptables_comment_search }}/ {$1="-D"; print $0}' | xargs -r -L1 iptables ${table}
done
#Should be cleaned after an Edge deployment
- name: Unload ifb kernel module
modprobe:
name: ifb
state: absent
failed_when: False
#Should be cleaned after an Edge deployment
- name: Killing dhcrelay agent
shell: |
for i in $(pgrep dhcrelay); do kill -9 ${i}; done
failed_when: False
- name: Remove vbmc package and nodes
hosts: hypervisor
gather_facts: yes
any_errors_fatal: true
become: true
vars_files:
- vars/hypervisor.yml
tasks:
- name: include vbmc's cleanup task
include_role:
name: vbmc
vars:
action: "cleanup"
prefix: "{{ provision.prefix|default('') }}"
- block:
- name: Get all deployments
set_fact:
deployments_info: "{{ deployments_info|default({})|combine({item.key : item.value}) }}"
when: prefix not in item.key
with_dict: "{{ ansible_local.deployment_info }}"
- name: Create running deployment custom fact
template:
src: deployments.fact.j2
dest: "{{ custom_facts }}/deployment_info.fact"
mode: 0644
when: provision.prefix is defined
- name: Make sure that we don't have deployment_info facts at all in case of full cleanup
file:
path: "{{ custom_facts }}/deployment_info.fact"
state: absent
when: provision.prefix is not defined
- name: Clean old inventory file
hosts: localhost
gather_facts: no
tasks:
- file:
dest: "{{ inventory_dir }}/hosts"
state: link
src: "local_hosts"