This repository was archived by the owner on Jun 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathteardown-playbook.yaml
213 lines (187 loc) · 5.27 KB
/
teardown-playbook.yaml
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
---
- hosts: all
user: "{{ remote_user }}"
become: yes
tasks:
- name: Remove certificate
file:
path: "{{ cert_dir }}/webproxy.crt"
state: absent
- name: update_cert_index
command: "{{ cert_bin }}"
changed_when: false
- name: get file stat to be able to perform check in the following task
stat:
path: /etc/systemd/system/kube-issue-32728-fix.service
register: service_32728
- name: Disable the fix for 32728
systemd:
name: kube-issue-32728-fix.service
state: stopped
enabled: no
when: service_32728.stat.exists
- name: Remove systemd unit file for 32728 fix (symlinks in /sys)
file:
path: /etc/systemd/system/kube-issue-32728-fix.service
state: absent
when: service_32728.stat.exists
- name: Remove python bootstrap file
file:
path: "{{ ansible_pypy_bootstrap_file }}"
state: absent
- name: Remove python interpreter
raw: "rm -rf {{ ansible_python_interpreter }} {{ ansible_pypy_home }}"
- hosts: masters:workers
user: "{{ remote_user }}"
become: yes
tasks:
- name: Remove kubernetes repository
yum_repository:
name: Kubernetes
state: absent
ignore_errors: yes
- name: Remove docker repository
yum_repository:
name: Docker
state: absent
ignore_errors: yes
- name: Stop services
command: timeout 15 /bin/systemctl stop {{ item }}
loop:
- kubelet
- docker
ignore_errors: yes
changed_when: false
- name: Disable services
command: timeout 15 /bin/systemctl disable {{ item }}
loop:
- kubelet
- docker
ignore_errors: yes
changed_when: false
- name: Remove files
file:
path: "{{ item }}"
state: absent
loop:
- /etc/systemd/system/docker.service.d
- /etc/systemd/system/kubelet.service
- /etc/kubernetes
- name: Unmount docker net resources
command: /bin/umount /run/docker/netns/*
ignore_errors: yes
- name: Unmount docker resources
command: /bin/umount /var/lib/docker/overlay
ignore_errors: yes
register: unmount_result
changed_when: false
- name: Find overlay pids to kill
shell: "lsof | grep '/var/lib/docker/overlay' | awk '{print $2}'"
register: overlay_pids
when: unmount_result.stderr | search("busy")
- name: Kill running overlay pids
shell: "kill -9 {{ item }}"
loop: "{{ overlay_pids.stdout_lines|flatten(levels=1) }}"
when: unmount_result.stderr | search("busy") and overlay_pids | length > 0
- name: Get mounted kubelet resources
shell: "mount | grep /var/lib/kubelet/pods | cut -d ' ' -f 3"
register: kubelet_resources
ignore_errors: yes
changed_when: false
tags:
- skip_ansible_lint
- name: umount kubelet resources
command: "umount {{ item }}"
when: kubelet_resources.stdout_lines|length > 0
loop: "{{ kubelet_resources.stdout_lines|flatten(levels=1) }}"
- hosts: masters
user: "{{ remote_user }}"
become: yes
tasks:
- name: Remove files
file:
path: "{{ item }}"
state: absent
loop:
- /etc/sensu/conf.d/nais_master_metrics.json
- hosts: etcd
user: "{{ remote_user }}"
become: yes
tasks:
- name: Disable etcd
systemd:
name: etcd
enabled: no
state: stopped
ignore_errors: yes
- name: Remove files
file:
path: "{{ item }}"
state: absent
loop:
- "{{ install_dir }}/bin/etcd-{{etcd_version}}"
- "{{ install_dir }}/bin/etcd"
- "{{ install_dir }}/bin/etcdctl-{{etcd_version}}"
- "{{ install_dir }}/bin/etcdctl"
- /var/lib/etcd
- /etc/systemd/system/etcd.service
- /etc/ssl/etcd
- hosts: workers
user: "{{ remote_user }}"
become: yes
tasks:
- name: Remove files
file:
path: /etc/sensu/conf.d/nais_worker_metrics.json
state: absent
- hosts: localhost
tasks:
- name: Remove target folder
file:
path: target
state: absent
- hosts: masters:workers
user: "{{ remote_user }}"
become: yes
tasks:
- name: Stop services
systemd:
name: "{{ item }}"
state: stopped
enabled: no
loop:
- kube-proxy
- flannel
ignore_errors: yes
- name: Remove files
file:
path: "{{ item }}"
state: absent
loop:
- /etc/systemd/system/kubelet.service
- "{{ install_dir }}/bin/kube-proxy*"
- "{{ install_dir }}/bin/kubelet*"
- "{{ install_dir }}/bin/kubectl*"
- /etc/systemd/system/kube-proxy.service
- "{{ install_dir }}/libexec/mk-docker-opts.sh"
- /etc/systemd/system/flannel.service
- /etc/systemd/system/docker.service
- /run/docker_opts.env
- /run/flannel/subnet.env
- /var/lib/docker
- /var/lib/dockershim
- /var/lib/kubelet
- /var/lib/kubernetes
- /var/run/flannel
- /var/run/kubernetes
- /run/flannel
- /run/kubernetes
- /root/.docker
- name: Remove flannel interface
command: ip link delete flannel.1
ignore_errors: yes
changed_when: false
- name: Remove nais sensu check directory
file:
path: /etc/sensu/plugins/metrics/nais
state: absent