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.

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