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.

200 lines
4.6 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 | remove all cri-o containers
  57. shell: "crictl ps -aq | xargs -r crictl rm"
  58. register: remove_all_crio_containers
  59. retries: 4
  60. until: remove_all_crio_containers.rc == 0
  61. delay: 5
  62. tags:
  63. - crio
  64. when: container_manager == 'crio'
  65. - name: reset | gather mounted kubelet dirs
  66. shell: mount | grep /var/lib/kubelet/ | awk '{print $3}' | tac
  67. check_mode: no
  68. register: mounted_dirs
  69. tags:
  70. - mounts
  71. - name: reset | unmount kubelet dirs
  72. command: umount {{item}}
  73. with_items: '{{ mounted_dirs.stdout_lines }}'
  74. register: umount_dir
  75. retries: 4
  76. until: umount_dir.rc == 0
  77. delay: 5
  78. tags:
  79. - mounts
  80. - name: flush iptables
  81. iptables:
  82. table: "{{ item }}"
  83. flush: yes
  84. with_items:
  85. - filter
  86. - nat
  87. when: flush_iptables|bool
  88. tags:
  89. - iptables
  90. - name: reset | delete some files and directories
  91. file:
  92. path: "{{ item }}"
  93. state: absent
  94. with_items:
  95. - "{{kube_config_dir}}"
  96. - /var/lib/kubelet
  97. - /root/.kube
  98. - /root/.helm
  99. - "{{ etcd_data_dir }}"
  100. - /var/lib/etcd-events
  101. - /etc/ssl/etcd
  102. - /var/log/calico
  103. - /etc/cni
  104. - /etc/nginx
  105. - /etc/dnsmasq.d
  106. - /etc/dnsmasq.conf
  107. - /etc/dnsmasq.d-available
  108. - /etc/etcd.env
  109. - /etc/calico
  110. - /etc/weave.env
  111. - /opt/cni
  112. - /etc/dhcp/dhclient.d/zdnsupdate.sh
  113. - /etc/dhcp/dhclient-exit-hooks.d/zdnsupdate
  114. - /run/flannel
  115. - /etc/flannel
  116. - /run/kubernetes
  117. - /usr/local/share/ca-certificates/etcd-ca.crt
  118. - /usr/local/share/ca-certificates/kube-ca.crt
  119. - /usr/local/share/ca-certificates/vault-ca.crt
  120. - /etc/ssl/certs/etcd-ca.pem
  121. - /etc/ssl/certs/kube-ca.pem
  122. - /etc/ssl/certs/vault-ca.crt
  123. - /etc/pki/ca-trust/source/anchors/etcd-ca.crt
  124. - /etc/pki/ca-trust/source/anchors/kube-ca.crt
  125. - /etc/pki/ca-trust/source/anchors/vault-ca.crt
  126. - /etc/vault
  127. - /var/log/pods/
  128. - "{{ bin_dir }}/kubelet"
  129. - "{{ bin_dir }}/etcd-scripts"
  130. - "{{ bin_dir }}/etcd"
  131. - "{{ bin_dir }}/etcd-events"
  132. - "{{ bin_dir }}/etcdctl"
  133. - "{{ bin_dir }}/kubernetes-scripts"
  134. - "{{ bin_dir }}/kubectl"
  135. - "{{ bin_dir }}/kubeadm"
  136. - "{{ bin_dir }}/helm"
  137. - "{{ bin_dir }}/calicoctl"
  138. - "{{ bin_dir }}/calico-upgrade"
  139. - "{{ bin_dir }}/weave"
  140. - /var/lib/rkt
  141. - /etc/vault
  142. ignore_errors: yes
  143. tags:
  144. - files
  145. - name: reset | remove dns settings from dhclient.conf
  146. blockinfile:
  147. dest: "{{ item }}"
  148. state: absent
  149. follow: yes
  150. marker: "# Ansible entries {mark}"
  151. failed_when: false
  152. with_items:
  153. - /etc/dhclient.conf
  154. - /etc/dhcp/dhclient.conf
  155. tags:
  156. - files
  157. - dns
  158. - name: reset | remove host entries from /etc/hosts
  159. blockinfile:
  160. dest: "/etc/hosts"
  161. state: absent
  162. follow: yes
  163. marker: "# Ansible inventory hosts {mark}"
  164. tags:
  165. - files
  166. - dns
  167. - name: reset | include file with reset tasks specific to the network_plugin if exists
  168. include_tasks: "{{ (role_path + '/../network_plugin/' + kube_network_plugin + '/tasks/reset.yml') | realpath }}"
  169. when:
  170. - kube_network_plugin in ['flannel', 'cilium']
  171. tags:
  172. - network
  173. - name: reset | Restart network
  174. service:
  175. name: >-
  176. {% if ansible_os_family == "RedHat" -%}
  177. network
  178. {%- elif ansible_os_family == "Debian" -%}
  179. networking
  180. {%- endif %}
  181. state: restarted
  182. when: ansible_os_family not in ["CoreOS", "Container Linux by CoreOS"] and reset_restart_network
  183. tags:
  184. - services
  185. - network