-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdestroy-ipi-lab.yml
92 lines (76 loc) · 3.1 KB
/
destroy-ipi-lab.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
- hosts: localhost
gather_facts: False
environment:
PATH: "{{ playbook_dir }}/bin:{{ ansible_env.PATH }}"
GOVC_USERNAME: "{{ vcenter.admin_username }}"
GOVC_PASSWORD: "{{ vcenter.admin_password }}"
GOVC_URL: "https://{{ vcenter.ip }}"
GOVC_DATACENTER: "{{ vcenter.datacenter }}"
GOVC_INSECURE: 1
tasks:
- name: stat /etc/resolv.conf.backup-ipi
stat:
path: /etc/resolv.conf.backup-ipi
register: resolv_conf_backup
when: config_local_dns is defined
- name: Get service_facts
service_facts:
when: config_local_dns is defined
- name: Restore backup of /etc/resolv.conf
copy:
src: /etc/resolv.conf.backup-ipi
dest: /etc/resolv.conf
mode: '0644'
when:
- config_local_dns is defined
- resolv_conf_backup.stat.exists
- ansible_facts.services["systemd-resolved.service"].state != "running"
- name: stat {{ config.cluster_domain }}.conf
stat:
path: "/etc/systemd/resolved.conf.d/{{ config.cluster_domain }}.conf"
register: resolved_conf
when: config_local_dns is defined
- name: Delete resolved conf file
file:
path: "/etc/systemd/resolved.conf.d/{{ config.cluster_domain }}.conf"
state: absent
become: yes
when:
- config_local_dns is defined
- resolved_conf.stat.exists
- ansible_facts.services["systemd-resolved.service"].state == "running"
- name: Restart systemd-resolved service
service:
name: systemd-resolved
state: restarted
become: yes
when:
- config_local_dns is defined
- ansible_facts.services["systemd-resolved.service"].state == "running"
- name: Set the datacenter variable
set_fact:
datacenter: "{{ vcenter.datacenter }}"
- name: Get Cluster infraID
command: jq -r .infraID "{{ playbook_dir }}/install-dir/metadata.json" # noqa 301
register: infraID
- name: Set the vcenter.infraID fact
set_fact:
vcenter_folder: "{{ infraID.stdout }}"
- name: Delete Bootstrap
command: "govc vm.destroy {{ infraID.stdout }}-{{ bootstrap_vm.name }}" # noqa 301
when: bootstrap is defined
- name: Set the vcenter.folder_absolute_path if not provided
set_fact:
vcenter: "{{ vcenter | combine({'folder_absolute_path': '/'+datacenter+'/vm/'+vcenter_folder}, recursive=True) }}"
- name: Delete Cluster
shell: "{{ playbook_dir }}/bin/govc find {{ vcenter.folder_absolute_path | quote }} -type m | awk -F/ '{ print $NF }' | xargs {{ playbook_dir }}/bin/govc vm.destroy" # noqa 301 306
when: cluster is defined
- name: Delete VM Folder
command: "{{ playbook_dir }}/bin/govc object.destroy {{ vcenter.folder_absolute_path }}" # noqa 301
when: cluster is defined
- name: Delete VM Tag
command: "{{ playbook_dir }}/bin/govc tags.rm {{ infraID.stdout }}" # noqa 301
when: cluster is defined
- name: Delete VM Tag Category
command: "{{ playbook_dir }}/bin/govc tags.category.rm {{ infraID.stdout }}" # noqa 301
when: cluster is defined