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.

210 lines
4.7 KiB

7 years ago
7 years ago
7 years ago
  1. ---
  2. - name: reset | stop services
  3. service:
  4. name: "{{ item }}"
  5. state: stopped
  6. with_items:
  7. - kubelet
  8. - vault
  9. - etcd
  10. - etcd-events
  11. failed_when: false
  12. tags:
  13. - services
  14. - name: reset | remove services
  15. file:
  16. path: "/etc/systemd/system/{{ item }}.service"
  17. state: absent
  18. with_items:
  19. - kubelet
  20. - etcd
  21. - etcd-events
  22. - vault
  23. - calico-node
  24. register: services_removed
  25. tags:
  26. - services
  27. - name: reset | remove docker dropins
  28. file:
  29. path: "/etc/systemd/system/docker.service.d/{{ item }}"
  30. state: absent
  31. with_items:
  32. - docker-dns.conf
  33. - docker-options.conf
  34. - http-proxy.conf
  35. register: docker_dropins_removed
  36. tags:
  37. - docker
  38. - name: reset | systemctl daemon-reload
  39. command: systemctl daemon-reload
  40. when: services_removed.changed or docker_dropins_removed.changed
  41. - name: reset | remove all containers
  42. shell: "{{ docker_bin_dir }}/docker ps -aq | xargs -r docker rm -fv"
  43. register: remove_all_containers
  44. retries: 4
  45. until: remove_all_containers.rc == 0
  46. delay: 5
  47. tags:
  48. - docker
  49. - name: reset | restart docker if needed
  50. service:
  51. name: docker
  52. state: restarted
  53. when: docker_dropins_removed.changed
  54. tags:
  55. - docker
  56. - name: reset | gather mounted kubelet dirs
  57. shell: mount | grep /var/lib/kubelet | awk '{print $3}' | tac
  58. check_mode: no
  59. register: mounted_dirs
  60. tags:
  61. - mounts
  62. - name: reset | unmount kubelet dirs
  63. command: umount {{item}}
  64. with_items: '{{ mounted_dirs.stdout_lines }}'
  65. register: umount_dir
  66. retries: 4
  67. until: umount_dir.rc == 0
  68. delay: 5
  69. tags:
  70. - mounts
  71. - name: flush iptables
  72. iptables:
  73. table: "{{ item }}"
  74. flush: yes
  75. with_items:
  76. - filter
  77. - nat
  78. when: flush_iptables|bool
  79. tags:
  80. - iptables
  81. - name: reset | delete some files and directories
  82. file:
  83. path: "{{ item }}"
  84. state: absent
  85. with_items:
  86. - "{{kube_config_dir}}"
  87. - /var/lib/kubelet
  88. - /root/.kube
  89. - /root/.helm
  90. - "{{ etcd_data_dir }}"
  91. - /var/lib/etcd-events
  92. - /etc/ssl/etcd
  93. - /var/log/calico
  94. - /etc/cni
  95. - /etc/nginx
  96. - /etc/dnsmasq.d
  97. - /etc/dnsmasq.conf
  98. - /etc/dnsmasq.d-available
  99. - /etc/etcd.env
  100. - /etc/calico
  101. - /etc/weave.env
  102. - /opt/cni
  103. - /etc/dhcp/dhclient.d/zdnsupdate.sh
  104. - /etc/dhcp/dhclient-exit-hooks.d/zdnsupdate
  105. - /run/flannel
  106. - /etc/flannel
  107. - /run/kubernetes
  108. - /usr/local/share/ca-certificates/etcd-ca.crt
  109. - /usr/local/share/ca-certificates/kube-ca.crt
  110. - /usr/local/share/ca-certificates/vault-ca.crt
  111. - /etc/ssl/certs/etcd-ca.pem
  112. - /etc/ssl/certs/kube-ca.pem
  113. - /etc/ssl/certs/vault-ca.crt
  114. - /etc/pki/ca-trust/source/anchors/etcd-ca.crt
  115. - /etc/pki/ca-trust/source/anchors/kube-ca.crt
  116. - /etc/pki/ca-trust/source/anchors/vault-ca.crt
  117. - /etc/vault
  118. - /var/log/pods/
  119. - "{{ bin_dir }}/kubelet"
  120. - "{{ bin_dir }}/etcd-scripts"
  121. - "{{ bin_dir }}/etcd"
  122. - "{{ bin_dir }}/etcd-events"
  123. - "{{ bin_dir }}/etcdctl"
  124. - "{{ bin_dir }}/kubernetes-scripts"
  125. - "{{ bin_dir }}/kubectl"
  126. - "{{ bin_dir }}/kubeadm"
  127. - "{{ bin_dir }}/helm"
  128. - "{{ bin_dir }}/calicoctl"
  129. - "{{ bin_dir }}/weave"
  130. - /var/lib/rkt
  131. - /etc/vault
  132. ignore_errors: yes
  133. tags:
  134. - files
  135. - name: reset | remove dns settings from dhclient.conf
  136. blockinfile:
  137. dest: "{{ item }}"
  138. state: absent
  139. follow: yes
  140. marker: "# Ansible entries {mark}"
  141. failed_when: false
  142. with_items:
  143. - /etc/dhclient.conf
  144. - /etc/dhcp/dhclient.conf
  145. tags:
  146. - files
  147. - dns
  148. - name: reset | remove host entries from /etc/hosts
  149. blockinfile:
  150. dest: "/etc/hosts"
  151. state: absent
  152. follow: yes
  153. marker: "# Ansible inventory hosts {mark}"
  154. tags:
  155. - files
  156. - dns
  157. - name: reset | check cni network device
  158. stat:
  159. path: /sys/class/net/cni0
  160. register: cni
  161. when: kube_network_plugin == 'flannel'
  162. tags:
  163. - flannel
  164. - name: reset | remove the network device created by the flannel
  165. command: ip link del cni0
  166. when: kube_network_plugin == 'flannel' and cni.stat.exists
  167. tags:
  168. - flannel
  169. - name: reset | check flannel network device
  170. stat:
  171. path: /sys/class/net/flannel.1
  172. register: flannel
  173. when: kube_network_plugin == 'flannel'
  174. tags:
  175. - flannel
  176. - name: reset | remove the network device created by the flannel
  177. command: ip link del flannel.1
  178. when: kube_network_plugin == 'flannel' and flannel.stat.exists
  179. tags:
  180. - flannel
  181. - name: reset | Restart network
  182. service:
  183. name: >-
  184. {% if ansible_os_family == "RedHat" -%}
  185. network
  186. {%- elif ansible_os_family == "Debian" -%}
  187. networking
  188. {%- endif %}
  189. state: restarted
  190. when: ansible_os_family not in ["CoreOS", "Container Linux by CoreOS"] and reset_restart_network
  191. tags:
  192. - services
  193. - network