uninstall_openshift.yml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. # This deletes *ALL* Origin and OpenShift Container Platform content installed by
  2. # ansible. This includes:
  3. #
  4. # configuration
  5. # containers
  6. # example templates and imagestreams
  7. # images
  8. # RPMs
  9. ---
  10. - hosts: OSEv3:children
  11. become: yes
  12. tasks:
  13. - name: Detecting Operating System
  14. shell: ls /run/ostree-booted
  15. ignore_errors: yes
  16. failed_when: false
  17. register: ostree_output
  18. # Since we're not calling openshift_facts we'll do this for now
  19. - set_fact:
  20. openshift_is_atomic: "{{ ostree_output.rc == 0 }}"
  21. openshift_is_containerized: "{{ ostree_output.rc == 0 or containerized | default(false) | bool }}"
  22. # Stop services on all hosts prior to removing files.
  23. - hosts: nodes
  24. become: yes
  25. tasks:
  26. - name: Remove dnsmasq dispatcher
  27. file:
  28. path: "{{ item }}"
  29. state: absent
  30. with_items:
  31. - /etc/dnsmasq.d/origin-dns.conf
  32. - /etc/dnsmasq.d/origin-upstream-dns.conf
  33. - /etc/dnsmasq.d/openshift-ansible.conf
  34. - /etc/NetworkManager/dispatcher.d/99-origin-dns.sh
  35. - service:
  36. name: NetworkManager
  37. state: restarted
  38. - name: Stop services
  39. service: name={{ item }} state=stopped
  40. with_items:
  41. - atomic-openshift-node
  42. - openshift-node
  43. - origin-node
  44. failed_when: false
  45. - name: Stop OVS service
  46. service: name=openvswitch state=stopped
  47. failed_when: false
  48. when: openshift_use_openshift_sdn | default(True) | bool
  49. - hosts: etcd
  50. become: yes
  51. tasks:
  52. - name: Stop services
  53. service: name={{ item }} state=stopped
  54. with_items:
  55. - etcd
  56. failed_when: false
  57. - hosts: lb
  58. become: yes
  59. tasks:
  60. - name: Stop services
  61. service: name={{ item }} state=stopped
  62. with_items:
  63. - haproxy
  64. failed_when: false
  65. - hosts: nodes
  66. become: yes
  67. vars:
  68. node_dirs:
  69. - "/etc/origin"
  70. - "/var/lib/origin"
  71. tasks:
  72. - name: unmask services
  73. command: systemctl unmask "{{ item }}"
  74. changed_when: False
  75. failed_when: False
  76. with_items:
  77. - firewalld
  78. - block:
  79. - block:
  80. - name: Remove packages
  81. package: name={{ item }} state=absent
  82. with_items:
  83. - atomic-openshift
  84. - atomic-openshift-clients
  85. - atomic-openshift-excluder
  86. - atomic-openshift-docker-excluder
  87. - atomic-openshift-node
  88. - atomic-openshift-sdn-ovs
  89. - atomic-openshift-hyperkube
  90. - cockpit-bridge
  91. - cockpit-docker
  92. - cockpit-system
  93. - cockpit-ws
  94. - kubernetes-client
  95. - openshift
  96. - openshift-node
  97. - openshift-sdn
  98. - openshift-sdn-ovs
  99. - origin
  100. - origin-excluder
  101. - origin-docker-excluder
  102. - origin-clients
  103. - origin-node
  104. - origin-sdn-ovs
  105. - origin-hyperkube
  106. - tuned-profiles-atomic-openshift-node
  107. - tuned-profiles-origin-node
  108. register: result
  109. until: result is succeeded
  110. - name: Remove OVS package
  111. package: name=openvswitch state=absent
  112. register: result
  113. until: result is succeeded
  114. when: openshift_use_openshift_sdn | default(True) | bool
  115. - name: Remove flannel package
  116. package: name=flannel state=absent
  117. when: openshift_use_flannel | default(false) | bool
  118. register: result
  119. until: result is succeeded
  120. when: not openshift_is_atomic | bool
  121. - shell: systemctl reset-failed
  122. changed_when: False
  123. - shell: systemctl daemon-reload
  124. changed_when: False
  125. - name: Remove br0 interface
  126. shell: ovs-vsctl del-br br0
  127. changed_when: False
  128. failed_when: False
  129. when: openshift_use_openshift_sdn | default(True) | bool
  130. - name: Remove linux interfaces
  131. shell: ip link del "{{ item }}"
  132. changed_when: False
  133. failed_when: False
  134. with_items:
  135. - lbr0
  136. - vlinuxbr
  137. - vovsbr
  138. when: openshift_use_openshift_sdn | default(True) | bool
  139. - name: Remove virtual devices
  140. command: nmcli delete device "{{ item }}"
  141. failed_when: False
  142. with_items:
  143. - tun0
  144. when: openshift_use_openshift_sdn | default(True) | bool
  145. when: openshift_remove_all | default(true) | bool
  146. - shell: atomic uninstall "{{ item }}"-node
  147. changed_when: False
  148. failed_when: False
  149. with_items:
  150. - openshift-enterprise
  151. - origin
  152. - shell: atomic uninstall "{{ item }}"
  153. changed_when: False
  154. failed_when: False
  155. with_items:
  156. - etcd
  157. - shell: atomic uninstall "{{ item }}"
  158. changed_when: False
  159. failed_when: False
  160. with_items:
  161. - openvswitch
  162. when: openshift_use_openshift_sdn | default(True) | bool
  163. - shell: find /var/lib/origin/openshift.local.volumes -type d -exec umount {} \; 2>/dev/null || true
  164. changed_when: False
  165. - shell: docker rm -f "{{ item }}"-master "{{ item }}"-node
  166. changed_when: False
  167. failed_when: False
  168. with_items:
  169. - openshift-enterprise
  170. - origin
  171. - shell: docker ps -a | grep Exited | egrep "{{ item }}" | awk '{print $1}'
  172. changed_when: False
  173. failed_when: False
  174. register: exited_containers_to_delete
  175. with_items:
  176. - openshift3/ose
  177. - openshift3/node
  178. - openshift3/openvswitch
  179. - openshift/origin
  180. - shell: "docker rm {{ item.stdout_lines | join(' ') }}"
  181. changed_when: False
  182. failed_when: False
  183. with_items: "{{ exited_containers_to_delete.results }}"
  184. - name: Remove k8s_ containters
  185. shell: docker ps -a -q -f name=k8s_ | xargs docker rm -f
  186. failed_when: False
  187. - block:
  188. - block:
  189. - shell: docker images | egrep {{ item }} | awk '{ print $3 }'
  190. changed_when: False
  191. failed_when: False
  192. register: images_to_delete
  193. with_items:
  194. - registry\.access\..*redhat\.com/openshift3
  195. - registry\.qe\.openshift\.com/.*
  196. - registry\.access\..*redhat\.com/rhel7/etcd
  197. - docker.io/openshift
  198. - shell: "docker rmi -f {{ item.stdout_lines | join(' ') }}"
  199. changed_when: False
  200. failed_when: False
  201. with_items: "{{ images_to_delete.results }}"
  202. when: openshift_uninstall_images | default(True) | bool
  203. - name: remove sdn drop files
  204. file:
  205. path: /run/openshift-sdn
  206. state: absent
  207. - name: Remove files owned by RPMs
  208. file: path={{ item }} state=absent
  209. with_items:
  210. - /etc/sysconfig/openshift-node
  211. - /run/openshift-sdn
  212. - name: Remove files owned by OVS RPM
  213. file: path=/etc/sysconfig/openvswitch state=absent
  214. when: openshift_use_openshift_sdn | default(True) | bool
  215. when: openshift_remove_all | default(True) | bool
  216. - find: path={{ item }} file_type=file
  217. register: files
  218. with_items:
  219. - "{{ node_dirs }}"
  220. - find: path={{ item }} file_type=directory
  221. register: directories
  222. with_items:
  223. - "{{ node_dirs }}"
  224. - file: path={{ item.1.path }} state=absent
  225. with_subelements:
  226. - "{{ files.results | default([]) }}"
  227. - files
  228. - file: path={{ item.1.path }} state=absent
  229. with_subelements:
  230. - "{{ directories.results | default([]) }}"
  231. - files
  232. - shell: systemctl daemon-reload
  233. changed_when: False
  234. - name: Remove remaining files
  235. file: path={{ item }} state=absent
  236. with_items:
  237. - /etc/ansible/facts.d/openshift.fact
  238. - /etc/openshift
  239. - /etc/openshift-sdn
  240. - /etc/pki/ca-trust/source/anchors/openshift-ca.crt
  241. - /etc/sysconfig/atomic-openshift-node
  242. - /etc/sysconfig/atomic-openshift-node-dep
  243. - /etc/sysconfig/openshift-node-dep
  244. - /etc/sysconfig/origin-node
  245. - /etc/sysconfig/origin-node
  246. - /etc/sysconfig/origin-node-dep
  247. - /etc/systemd/system/atomic-openshift-node-dep.service
  248. - /etc/systemd/system/atomic-openshift-node.service
  249. - /etc/systemd/system/atomic-openshift-node.service.wants
  250. - /etc/systemd/system/origin-node-dep.service
  251. - /etc/systemd/system/origin-node.service
  252. - /etc/systemd/system/origin-node.service.wants
  253. - name: Remove remaining OVS files
  254. file: path={{ item }} state=absent
  255. with_items:
  256. - /etc/systemd/system/openvswitch.service
  257. when: openshift_use_openshift_sdn | default(True) | bool
  258. - name: Rebuild ca-trust
  259. command: update-ca-trust
  260. - hosts: masters
  261. become: yes
  262. vars:
  263. master_dirs:
  264. - "/etc/origin"
  265. - "/var/lib/origin"
  266. tasks:
  267. - name: unmask services
  268. command: systemctl unmask "{{ item }}"
  269. changed_when: False
  270. failed_when: False
  271. with_items:
  272. - firewalld
  273. - atomic-openshift-master
  274. - name: Remove packages
  275. package: name={{ item }} state=absent
  276. when: not openshift_is_atomic | bool and openshift_remove_all | default(True) | bool
  277. with_items:
  278. - atomic-openshift
  279. - atomic-openshift-clients
  280. - atomic-openshift-excluder
  281. - atomic-openshift-docker-excluder
  282. - atomic-openshift-master
  283. - cockpit-bridge
  284. - cockpit-docker
  285. - cockpit-system
  286. - cockpit-ws
  287. - corosync
  288. - kubernetes-client
  289. - openshift
  290. - openshift-master
  291. - origin
  292. - origin-clients
  293. - origin-excluder
  294. - origin-docker-excluder
  295. - origin-master
  296. register: result
  297. until: result is succeeded
  298. - shell: systemctl reset-failed
  299. changed_when: False
  300. - shell: systemctl daemon-reload
  301. changed_when: False
  302. - name: Remove files owned by RPMs
  303. file: path={{ item }} state=absent
  304. with_items:
  305. - /etc/sysconfig/atomic-openshift-master
  306. when: openshift_remove_all | default(True) | bool
  307. - name: Remove files owned by OVS RPM
  308. file: path={{ item }} state=absent
  309. with_items:
  310. - /etc/sysconfig/openvswitch
  311. when:
  312. - openshift_remove_all | default(True) | bool
  313. - openshift_use_openshift_sdn | default(True) | bool
  314. - find: path={{ item }} file_type=file
  315. register: files
  316. with_items:
  317. - "{{ master_dirs }}"
  318. - find: path={{ item }} file_type=directory
  319. register: directories
  320. with_items:
  321. - "{{ master_dirs }}"
  322. - file: path={{ item.1.path }} state=absent
  323. with_subelements:
  324. - "{{ files.results | default([]) }}"
  325. - files
  326. - file: path={{ item.1.path }} state=absent
  327. with_subelements:
  328. - "{{ directories.results | default([]) }}"
  329. - files
  330. - set_fact:
  331. client_users: "{{ [ansible_ssh_user, 'root'] | unique }}"
  332. - name: Remove client kubeconfigs
  333. file:
  334. path: "~{{ item }}/.kube"
  335. state: absent
  336. with_items:
  337. - "{{ client_users }}"
  338. - name: Remove remaining files
  339. file: path={{ item }} state=absent
  340. with_items:
  341. - /etc/ansible/facts.d/openshift.fact
  342. - /etc/corosync
  343. - /usr/share/openshift/examples
  344. - /usr/local/bin/openshift
  345. - /usr/local/bin/oadm
  346. - /usr/local/bin/oc
  347. - /usr/local/bin/kubectl
  348. - /etc/flannel
  349. - name: Remove remaining OVS files
  350. file: path={{ item }} state=absent
  351. with_items:
  352. - /etc/systemd/system/openvswitch.service
  353. when: openshift_use_openshift_sdn | default(True) | bool
  354. - hosts: etcd
  355. become: yes
  356. vars:
  357. etcd_dirs:
  358. - "/etc/etcd"
  359. - "/var/lib/etcd"
  360. tasks:
  361. - name: unmask services
  362. command: systemctl unmask "{{ item }}"
  363. changed_when: False
  364. failed_when: False
  365. with_items:
  366. - etcd
  367. - etcd3
  368. - firewalld
  369. - name: Stop additional atomic services
  370. service: name={{ item }} state=stopped
  371. when: openshift_is_containerized | bool
  372. with_items:
  373. - etcd_container
  374. failed_when: false
  375. - name: Remove packages
  376. package: name={{ item }} state=absent
  377. when: not openshift_is_atomic | bool and openshift_remove_all | default(True) | bool
  378. with_items:
  379. - etcd
  380. - etcd3
  381. register: result
  382. until: result is succeeded
  383. - shell: systemctl reset-failed
  384. changed_when: False
  385. - shell: systemctl daemon-reload
  386. changed_when: False
  387. - find: path={{ item }} file_type=file
  388. register: files
  389. with_items:
  390. - "{{ etcd_dirs }}"
  391. - find: path={{ item }} file_type=directory
  392. register: directories
  393. with_items:
  394. - "{{ etcd_dirs }}"
  395. - file: path={{ item.1.path }} state=absent
  396. with_subelements:
  397. - "{{ files.results | default([]) }}"
  398. - files
  399. - file: path={{ item.1.path }} state=absent
  400. with_subelements:
  401. - "{{ directories.results | default([]) }}"
  402. - files
  403. # Intenationally using rm command over file module because if someone had mounted a filesystem
  404. # at /var/lib/etcd then the contents was not removed correctly
  405. - name: Remove etcd data
  406. shell: rm -rf /var/lib/etcd/*
  407. args:
  408. warn: no
  409. failed_when: false
  410. - name: Remove remaining files
  411. file: path={{ item }} state=absent
  412. with_items:
  413. - /etc/ansible/facts.d/openshift.fact
  414. - /etc/systemd/system/etcd_container.service
  415. - /etc/profile.d/etcdctl.sh
  416. - hosts: lb
  417. become: yes
  418. tasks:
  419. - name: unmask services
  420. command: systemctl unmask "{{ item }}"
  421. changed_when: False
  422. failed_when: False
  423. with_items:
  424. - firewalld
  425. - name: Remove packages
  426. package: name={{ item }} state=absent
  427. when: not openshift_is_atomic | bool and openshift_remove_all | default(True) | bool
  428. with_items:
  429. - haproxy
  430. register: result
  431. until: result is succeeded
  432. - shell: systemctl reset-failed
  433. changed_when: False
  434. - shell: systemctl daemon-reload
  435. changed_when: False
  436. - name: Remove remaining files
  437. file: path={{ item }} state=absent
  438. with_items:
  439. - /etc/ansible/facts.d/openshift.fact
  440. - /var/lib/haproxy/stats
  441. # Here we remove only limits.conf rather than directory, as users may put their files.
  442. # - /etc/systemd/system/haproxy.service.d
  443. - /etc/systemd/system/haproxy.service.d/limits.conf
  444. - /etc/systemd/system/haproxy.service