You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

305 lines
7.4 KiB

7 years ago
7 years ago
7 years ago
6 years ago
  1. ---
  2. - name: reset | include file with pre-reset tasks specific to the network_plugin if exists
  3. include_tasks: "{{ (role_path + '/../network_plugin/' + kube_network_plugin + '/tasks/pre-reset.yml') | realpath }}"
  4. when:
  5. - kube_network_plugin in ['contiv']
  6. tags:
  7. - network
  8. - name: reset | stop services
  9. service:
  10. name: "{{ item }}"
  11. state: stopped
  12. with_items:
  13. - kubelet
  14. - vault
  15. failed_when: false
  16. tags:
  17. - services
  18. - name: reset | remove services
  19. file:
  20. path: "/etc/systemd/system/{{ item }}.service"
  21. state: absent
  22. with_items:
  23. - kubelet
  24. - vault
  25. - calico-node
  26. register: services_removed
  27. tags:
  28. - services
  29. - name: reset | remove docker dropins
  30. file:
  31. path: "/etc/systemd/system/docker.service.d/{{ item }}"
  32. state: absent
  33. with_items:
  34. - docker-dns.conf
  35. - docker-options.conf
  36. - http-proxy.conf
  37. register: docker_dropins_removed
  38. tags:
  39. - docker
  40. - name: reset | systemctl daemon-reload
  41. systemd:
  42. daemon_reload: true
  43. when: services_removed.changed or docker_dropins_removed.changed
  44. - name: reset | remove all containers
  45. shell: "{{ docker_bin_dir }}/docker ps -aq | xargs -r docker rm -fv"
  46. register: remove_all_containers
  47. retries: 4
  48. until: remove_all_containers.rc == 0
  49. delay: 5
  50. when: container_manager == "docker"
  51. tags:
  52. - docker
  53. - name: reset | restart docker if needed
  54. service:
  55. name: docker
  56. state: restarted
  57. when: docker_dropins_removed.changed and container_manager == "docker"
  58. tags:
  59. - docker
  60. - name: reset | stop all cri containers
  61. shell: "crictl ps -aq | xargs -r crictl -t 60s stop"
  62. register: remove_all_cri_containers
  63. retries: 5
  64. until: remove_all_cri_containers.rc == 0
  65. delay: 5
  66. tags:
  67. - crio
  68. - containerd
  69. when: container_manager in ["crio", "containerd"]
  70. - name: reset | remove all cri containers
  71. shell: "crictl ps -aq | xargs -r crictl -t 60s rm"
  72. register: remove_all_cri_containers
  73. retries: 5
  74. until: remove_all_cri_containers.rc == 0
  75. delay: 5
  76. tags:
  77. - crio
  78. - containerd
  79. when: container_manager in ["crio", "containerd"] and deploy_container_engine|default(true)
  80. - name: reset | stop all cri pods
  81. shell: "crictl pods -q | xargs -r crictl -t 60s stopp"
  82. register: remove_all_cri_containers
  83. retries: 5
  84. until: remove_all_cri_containers.rc == 0
  85. delay: 5
  86. tags:
  87. - crio
  88. - containerd
  89. when: container_manager in ["crio", "containerd"]
  90. - name: reset | remove all cri pods
  91. shell: "crictl pods -q | xargs -r crictl -t 60s rmp"
  92. register: remove_all_cri_containers
  93. retries: 5
  94. until: remove_all_cri_containers.rc == 0
  95. delay: 5
  96. tags:
  97. - crio
  98. - containerd
  99. when: container_manager in ["crio", "containerd"]
  100. - name: reset | stop etcd services
  101. service:
  102. name: "{{ item }}"
  103. state: stopped
  104. with_items:
  105. - etcd
  106. - etcd-events
  107. failed_when: false
  108. tags:
  109. - services
  110. - name: reset | remove etcd services
  111. file:
  112. path: "/etc/systemd/system/{{ item }}.service"
  113. state: absent
  114. with_items:
  115. - etcd
  116. - etcd-events
  117. register: services_removed
  118. tags:
  119. - services
  120. - name: reset | gather mounted kubelet dirs
  121. shell: mount | grep /var/lib/kubelet/ | awk '{print $3}' | tac
  122. args:
  123. warn: false
  124. check_mode: no
  125. register: mounted_dirs
  126. tags:
  127. - mounts
  128. - name: reset | unmount kubelet dirs
  129. command: umount -f {{ item }}
  130. with_items: '{{ mounted_dirs.stdout_lines }}'
  131. register: umount_dir
  132. retries: 4
  133. until: umount_dir.rc == 0
  134. delay: 5
  135. tags:
  136. - mounts
  137. - name: flush iptables
  138. iptables:
  139. table: "{{ item }}"
  140. flush: yes
  141. with_items:
  142. - filter
  143. - nat
  144. when: flush_iptables|bool
  145. tags:
  146. - iptables
  147. - name: Clear IPVS virtual server table
  148. shell: "ipvsadm -C"
  149. when:
  150. - kube_proxy_mode == 'ipvs' and inventory_hostname in groups['k8s-cluster']
  151. - name: reset | check kube-ipvs0 network device
  152. stat:
  153. path: /sys/class/net/kube-ipvs0
  154. register: kube_ipvs0
  155. - name: reset | Remove kube-ipvs0
  156. command: "ip link del kube-ipvs0"
  157. when:
  158. - kube_proxy_mode == 'ipvs'
  159. - kube_ipvs0.stat.exists
  160. - name: reset | check nodelocaldns network device
  161. stat:
  162. path: /sys/class/net/nodelocaldns
  163. register: nodelocaldns_device
  164. - name: reset | Remove nodelocaldns
  165. command: "ip link del nodelocaldns"
  166. when:
  167. - enable_nodelocaldns|default(false)|bool
  168. - nodelocaldns_device.stat.exists
  169. - name: reset | delete some files and directories
  170. file:
  171. path: "{{ item }}"
  172. state: absent
  173. with_items:
  174. - "{{ kube_config_dir }}"
  175. - /var/lib/kubelet
  176. - "{{ ansible_env.HOME | default('/root') }}/.kube"
  177. - "{{ ansible_env.HOME | default('/root') }}/.helm"
  178. - "{{ etcd_data_dir }}"
  179. - /var/lib/etcd-events
  180. - /etc/ssl/etcd
  181. - /var/log/calico
  182. - /etc/cni
  183. - "{{ nginx_config_dir }}"
  184. - /etc/dnsmasq.d
  185. - /etc/dnsmasq.conf
  186. - /etc/dnsmasq.d-available
  187. - /etc/etcd.env
  188. - /etc/calico
  189. - /etc/weave.env
  190. - /opt/cni
  191. - /etc/dhcp/dhclient.d/zdnsupdate.sh
  192. - /etc/dhcp/dhclient-exit-hooks.d/zdnsupdate
  193. - /run/flannel
  194. - /etc/flannel
  195. - /run/kubernetes
  196. - /usr/local/share/ca-certificates/etcd-ca.crt
  197. - /usr/local/share/ca-certificates/kube-ca.crt
  198. - /usr/local/share/ca-certificates/vault-ca.crt
  199. - /etc/ssl/certs/etcd-ca.pem
  200. - /etc/ssl/certs/kube-ca.pem
  201. - /etc/ssl/certs/vault-ca.crt
  202. - /etc/pki/ca-trust/source/anchors/etcd-ca.crt
  203. - /etc/pki/ca-trust/source/anchors/kube-ca.crt
  204. - /etc/pki/ca-trust/source/anchors/vault-ca.crt
  205. - /etc/vault
  206. - /var/log/pods/
  207. - "{{ bin_dir }}/kubelet"
  208. - "{{ bin_dir }}/etcd-scripts"
  209. - "{{ bin_dir }}/etcd"
  210. - "{{ bin_dir }}/etcd-events"
  211. - "{{ bin_dir }}/etcdctl"
  212. - "{{ bin_dir }}/kubernetes-scripts"
  213. - "{{ bin_dir }}/kubectl"
  214. - "{{ bin_dir }}/kubeadm"
  215. - "{{ bin_dir }}/hyperkube"
  216. - "{{ bin_dir }}/helm"
  217. - "{{ bin_dir }}/calicoctl"
  218. - "{{ bin_dir }}/calicoctl.sh"
  219. - "{{ bin_dir }}/calico-upgrade"
  220. - "{{ bin_dir }}/weave"
  221. - "{{ bin_dir }}/crictl"
  222. - "{{ bin_dir }}/netctl"
  223. - /var/lib/cni
  224. - /etc/vault
  225. - /etc/contiv
  226. - /var/contiv
  227. - /run/contiv
  228. - /etc/openvswitch
  229. - /run/openvswitch
  230. - /var/lib/kube-router
  231. - /var/lib/calico
  232. - /etc/cilium
  233. - /run/calico
  234. ignore_errors: yes
  235. tags:
  236. - files
  237. - name: reset | remove dns settings from dhclient.conf
  238. blockinfile:
  239. path: "{{ item }}"
  240. state: absent
  241. marker: "# Ansible entries {mark}"
  242. failed_when: false
  243. with_items:
  244. - /etc/dhclient.conf
  245. - /etc/dhcp/dhclient.conf
  246. tags:
  247. - files
  248. - dns
  249. - name: reset | remove host entries from /etc/hosts
  250. blockinfile:
  251. path: "/etc/hosts"
  252. state: absent
  253. marker: "# Ansible inventory hosts {mark}"
  254. tags:
  255. - files
  256. - dns
  257. - name: reset | include file with reset tasks specific to the network_plugin if exists
  258. include_tasks: "{{ (role_path + '/../network_plugin/' + kube_network_plugin + '/tasks/reset.yml') | realpath }}"
  259. when:
  260. - kube_network_plugin in ['flannel', 'cilium', 'contiv', 'kube-router', 'calico']
  261. tags:
  262. - network
  263. - name: reset | Restart network
  264. service:
  265. name: >-
  266. {% if ansible_os_family == "RedHat" -%}
  267. network
  268. {%- elif ansible_distribution == "Ubuntu" and ansible_distribution_release == "bionic" -%}
  269. systemd-networkd
  270. {%- elif ansible_os_family == "Debian" -%}
  271. networking
  272. {%- endif %}
  273. state: restarted
  274. when:
  275. - ansible_os_family not in ["CoreOS", "Container Linux by CoreOS"]
  276. - reset_restart_network
  277. tags:
  278. - services
  279. - network