-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy path99_destroy-environment.yml
80 lines (70 loc) · 2.4 KB
/
99_destroy-environment.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
---
- name: Get a clean slate.
hosts: localhost
become: true
vars_files:
- vars/general/main.yml
- vars/multipass/main.yml
- vars/hashicorp/general.yml
- vars/hashicorp/ssl.yml
tasks:
- name: LOCALHOST
tags: localhost
block:
- name: Remove the comment block from the hosts file.
ansible.builtin.blockinfile:
backup: true
path: /etc/hosts
state: absent
block: |
# Added for the AT HashiCorp Demo - discard afterwards
- name: Remove the instances from the hosts file.
ansible.builtin.lineinfile:
dest: /etc/hosts
regexp: ".*{{ hostvars[item].ansible_host }} {{ item }}"
state: absent
with_items: "{{ groups.all }}"
- name: Remove items from known hosts file based on IP.
ansible.builtin.command: 'ssh-keygen -f "~/.ssh/known_hosts" -R "{{ hostvars[item].ansible_host }}"'
become: false
changed_when: true
with_items: "{{ groups.all }}"
- name: Remove items from known hosts file based on hostname.
ansible.builtin.command: 'ssh-keygen -f "~/.ssh/known_hosts" -R "{{ item }}"'
become: false
changed_when: true
with_items:
- "{{ multipass_instances.clients }}"
- "{{ multipass_instances.servers }}"
- name: MULTIPASS
tags: multipass
block:
- name: Auth against Multipass.
ansible.builtin.command: "multipass authenticate {{ multipass_passphrase }}"
no_log: true
changed_when: false
- name: Delete existing instances.
ansible.builtin.command: "multipass delete {{ item }}"
ignore_errors: true
changed_when: true
with_items:
- "{{ multipass_instances.clients }}"
- "{{ multipass_instances.servers }}"
- name: Purge the multipass inventory after deletion.
ansible.builtin.command: "multipass purge"
changed_when: false
- name: Remove inventory
tags: inventory
ansible.builtin.file:
path: inventory
state: absent
delegate_to: localhost
run_once: true
- name: Remove tokens
tags: tokens
become: false
ansible.builtin.file:
path: "{{ token_directory }}"
state: absent
delegate_to: localhost
run_once: true