uninstall_openshift.yml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  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: masters
  50. become: yes
  51. tasks:
  52. - name: Stop services
  53. service: name={{ item }} state=stopped
  54. with_items:
  55. - atomic-openshift-master
  56. - atomic-openshift-master-api
  57. - atomic-openshift-master-controllers
  58. - openshift-master
  59. - openshift-master-api
  60. - openshift-master-controllers
  61. - origin-master
  62. - origin-master-api
  63. - origin-master-controllers
  64. failed_when: false
  65. - hosts: etcd
  66. become: yes
  67. tasks:
  68. - name: Stop services
  69. service: name={{ item }} state=stopped
  70. with_items:
  71. - etcd
  72. failed_when: false
  73. - hosts: lb
  74. become: yes
  75. tasks:
  76. - name: Stop services
  77. service: name={{ item }} state=stopped
  78. with_items:
  79. - haproxy
  80. failed_when: false
  81. - hosts: nodes
  82. become: yes
  83. vars:
  84. node_dirs:
  85. - "/etc/origin"
  86. - "/var/lib/origin"
  87. tasks:
  88. - name: unmask services
  89. command: systemctl unmask "{{ item }}"
  90. changed_when: False
  91. failed_when: False
  92. with_items:
  93. - firewalld
  94. - block:
  95. - block:
  96. - name: Remove packages
  97. package: name={{ item }} state=absent
  98. with_items:
  99. - atomic-openshift
  100. - atomic-openshift-clients
  101. - atomic-openshift-excluder
  102. - atomic-openshift-docker-excluder
  103. - atomic-openshift-node
  104. - atomic-openshift-sdn-ovs
  105. - atomic-openshift-hyperkube
  106. - cockpit-bridge
  107. - cockpit-docker
  108. - cockpit-system
  109. - cockpit-ws
  110. - kubernetes-client
  111. - openshift
  112. - openshift-node
  113. - openshift-sdn
  114. - openshift-sdn-ovs
  115. - origin
  116. - origin-excluder
  117. - origin-docker-excluder
  118. - origin-clients
  119. - origin-node
  120. - origin-sdn-ovs
  121. - origin-hyperkube
  122. - tuned-profiles-atomic-openshift-node
  123. - tuned-profiles-origin-node
  124. register: result
  125. until: result is succeeded
  126. - name: Remove OVS package
  127. package: name=openvswitch state=absent
  128. register: result
  129. until: result is succeeded
  130. when: openshift_use_openshift_sdn | default(True) | bool
  131. - name: Remove flannel package
  132. package: name=flannel state=absent
  133. when: openshift_use_flannel | default(false) | bool
  134. register: result
  135. until: result is succeeded
  136. when: not openshift_is_atomic | bool
  137. - shell: systemctl reset-failed
  138. changed_when: False
  139. - shell: systemctl daemon-reload
  140. changed_when: False
  141. - name: Remove br0 interface
  142. shell: ovs-vsctl del-br br0
  143. changed_when: False
  144. failed_when: False
  145. when: openshift_use_openshift_sdn | default(True) | bool
  146. - name: Remove linux interfaces
  147. shell: ip link del "{{ item }}"
  148. changed_when: False
  149. failed_when: False
  150. with_items:
  151. - lbr0
  152. - vlinuxbr
  153. - vovsbr
  154. when: openshift_use_openshift_sdn | default(True) | bool
  155. - name: Remove virtual devices
  156. command: nmcli delete device "{{ item }}"
  157. failed_when: False
  158. with_items:
  159. - tun0
  160. when: openshift_use_openshift_sdn | default(True) | bool
  161. when: openshift_remove_all | default(true) | bool
  162. - shell: atomic uninstall "{{ item }}"-master-api
  163. changed_when: False
  164. failed_when: False
  165. with_items:
  166. - openshift-enterprise
  167. - origin
  168. - shell: atomic uninstall "{{ item }}"-master-controllers
  169. changed_when: False
  170. failed_when: False
  171. with_items:
  172. - openshift-enterprise
  173. - origin
  174. - shell: atomic uninstall "{{ item }}"-master
  175. changed_when: False
  176. failed_when: False
  177. with_items:
  178. - openshift-enterprise
  179. - origin
  180. - shell: atomic uninstall "{{ item }}"-node
  181. changed_when: False
  182. failed_when: False
  183. with_items:
  184. - openshift-enterprise
  185. - origin
  186. - shell: atomic uninstall "{{ item }}"
  187. changed_when: False
  188. failed_when: False
  189. with_items:
  190. - etcd
  191. - shell: atomic uninstall "{{ item }}"
  192. changed_when: False
  193. failed_when: False
  194. with_items:
  195. - openvswitch
  196. when: openshift_use_openshift_sdn | default(True) | bool
  197. - shell: find /var/lib/origin/openshift.local.volumes -type d -exec umount {} \; 2>/dev/null || true
  198. changed_when: False
  199. - shell: docker rm -f "{{ item }}"-master "{{ item }}"-node
  200. changed_when: False
  201. failed_when: False
  202. with_items:
  203. - openshift-enterprise
  204. - origin
  205. - shell: docker ps -a | grep Exited | egrep "{{ item }}" | awk '{print $1}'
  206. changed_when: False
  207. failed_when: False
  208. register: exited_containers_to_delete
  209. with_items:
  210. - openshift3/ose
  211. - openshift3/node
  212. - openshift3/openvswitch
  213. - openshift/origin
  214. - shell: "docker rm {{ item.stdout_lines | join(' ') }}"
  215. changed_when: False
  216. failed_when: False
  217. with_items: "{{ exited_containers_to_delete.results }}"
  218. - name: Remove k8s_ containters
  219. shell: docker ps -a -q -f name=k8s_ | xargs docker rm -f
  220. failed_when: False
  221. - block:
  222. - block:
  223. - shell: docker images | egrep {{ item }} | awk '{ print $3 }'
  224. changed_when: False
  225. failed_when: False
  226. register: images_to_delete
  227. with_items:
  228. - registry\.access\..*redhat\.com/openshift3
  229. - registry\.qe\.openshift\.com/.*
  230. - registry\.access\..*redhat\.com/rhel7/etcd
  231. - docker.io/openshift
  232. - shell: "docker rmi -f {{ item.stdout_lines | join(' ') }}"
  233. changed_when: False
  234. failed_when: False
  235. with_items: "{{ images_to_delete.results }}"
  236. when: openshift_uninstall_images | default(True) | bool
  237. - name: remove sdn drop files
  238. file:
  239. path: /run/openshift-sdn
  240. state: absent
  241. - name: Remove files owned by RPMs
  242. file: path={{ item }} state=absent
  243. with_items:
  244. - /etc/sysconfig/openshift-node
  245. - /run/openshift-sdn
  246. - name: Remove files owned by OVS RPM
  247. file: path=/etc/sysconfig/openvswitch state=absent
  248. when: openshift_use_openshift_sdn | default(True) | bool
  249. when: openshift_remove_all | default(True) | bool
  250. - find: path={{ item }} file_type=file
  251. register: files
  252. with_items:
  253. - "{{ node_dirs }}"
  254. - find: path={{ item }} file_type=directory
  255. register: directories
  256. with_items:
  257. - "{{ node_dirs }}"
  258. - file: path={{ item.1.path }} state=absent
  259. with_subelements:
  260. - "{{ files.results | default([]) }}"
  261. - files
  262. - file: path={{ item.1.path }} state=absent
  263. with_subelements:
  264. - "{{ directories.results | default([]) }}"
  265. - files
  266. - shell: systemctl daemon-reload
  267. changed_when: False
  268. - name: Remove remaining files
  269. file: path={{ item }} state=absent
  270. with_items:
  271. - /etc/ansible/facts.d/openshift.fact
  272. - /etc/openshift
  273. - /etc/openshift-sdn
  274. - /etc/pki/ca-trust/source/anchors/openshift-ca.crt
  275. - /etc/sysconfig/atomic-openshift-node
  276. - /etc/sysconfig/atomic-openshift-node-dep
  277. - /etc/sysconfig/openshift-node-dep
  278. - /etc/sysconfig/origin-node
  279. - /etc/sysconfig/origin-node
  280. - /etc/sysconfig/origin-node-dep
  281. - /etc/systemd/system/atomic-openshift-node-dep.service
  282. - /etc/systemd/system/atomic-openshift-node.service
  283. - /etc/systemd/system/atomic-openshift-node.service.wants
  284. - /etc/systemd/system/origin-node-dep.service
  285. - /etc/systemd/system/origin-node.service
  286. - /etc/systemd/system/origin-node.service.wants
  287. - name: Remove remaining OVS files
  288. file: path={{ item }} state=absent
  289. with_items:
  290. - /etc/systemd/system/openvswitch.service
  291. when: openshift_use_openshift_sdn | default(True) | bool
  292. - name: Rebuild ca-trust
  293. command: update-ca-trust
  294. - hosts: masters
  295. become: yes
  296. vars:
  297. master_dirs:
  298. - "/etc/origin"
  299. - "/var/lib/origin"
  300. tasks:
  301. - name: unmask services
  302. command: systemctl unmask "{{ item }}"
  303. changed_when: False
  304. failed_when: False
  305. with_items:
  306. - firewalld
  307. - atomic-openshift-master
  308. - name: Remove packages
  309. package: name={{ item }} state=absent
  310. when: not openshift_is_atomic | bool and openshift_remove_all | default(True) | bool
  311. with_items:
  312. - atomic-openshift
  313. - atomic-openshift-clients
  314. - atomic-openshift-excluder
  315. - atomic-openshift-docker-excluder
  316. - atomic-openshift-master
  317. - cockpit-bridge
  318. - cockpit-docker
  319. - cockpit-system
  320. - cockpit-ws
  321. - corosync
  322. - kubernetes-client
  323. - openshift
  324. - openshift-master
  325. - origin
  326. - origin-clients
  327. - origin-excluder
  328. - origin-docker-excluder
  329. - origin-master
  330. register: result
  331. until: result is succeeded
  332. - shell: systemctl reset-failed
  333. changed_when: False
  334. - shell: systemctl daemon-reload
  335. changed_when: False
  336. - name: Remove files owned by RPMs
  337. file: path={{ item }} state=absent
  338. with_items:
  339. - /etc/sysconfig/atomic-openshift-master
  340. when: openshift_remove_all | default(True) | bool
  341. - name: Remove files owned by OVS RPM
  342. file: path={{ item }} state=absent
  343. with_items:
  344. - /etc/sysconfig/openvswitch
  345. when:
  346. - openshift_remove_all | default(True) | bool
  347. - openshift_use_openshift_sdn | default(True) | bool
  348. - find: path={{ item }} file_type=file
  349. register: files
  350. with_items:
  351. - "{{ master_dirs }}"
  352. - find: path={{ item }} file_type=directory
  353. register: directories
  354. with_items:
  355. - "{{ master_dirs }}"
  356. - file: path={{ item.1.path }} state=absent
  357. with_subelements:
  358. - "{{ files.results | default([]) }}"
  359. - files
  360. - file: path={{ item.1.path }} state=absent
  361. with_subelements:
  362. - "{{ directories.results | default([]) }}"
  363. - files
  364. - set_fact:
  365. client_users: "{{ [ansible_ssh_user, 'root'] | unique }}"
  366. - name: Remove client kubeconfigs
  367. file:
  368. path: "~{{ item }}/.kube"
  369. state: absent
  370. with_items:
  371. - "{{ client_users }}"
  372. - name: Remove remaining files
  373. file: path={{ item }} state=absent
  374. with_items:
  375. - /etc/ansible/facts.d/openshift.fact
  376. - /etc/corosync
  377. - /etc/openshift
  378. - /etc/openshift-sdn
  379. - /etc/systemd/system/atomic-openshift-master.service
  380. - /etc/systemd/system/atomic-openshift-master-api.service
  381. - /etc/systemd/system/atomic-openshift-master-controllers.service
  382. - /etc/systemd/system/origin-master.service
  383. - /etc/systemd/system/origin-master-api.service
  384. - /etc/systemd/system/origin-master-controllers.service
  385. - /etc/sysconfig/atomic-openshift-master-api
  386. - /etc/sysconfig/atomic-openshift-master-controllers
  387. - /etc/sysconfig/origin-master
  388. - /etc/sysconfig/origin-master-api
  389. - /etc/sysconfig/origin-master-controllers
  390. - /etc/sysconfig/openshift-master
  391. - /etc/sysconfig/origin-master
  392. - /etc/sysconfig/origin-master-api
  393. - /etc/sysconfig/origin-master-controllers
  394. - /usr/share/openshift/examples
  395. - /usr/lib/systemd/system/atomic-openshift-master-api.service
  396. - /usr/lib/systemd/system/atomic-openshift-master-controllers.service
  397. - /usr/lib/systemd/system/origin-master-api.service
  398. - /usr/lib/systemd/system/origin-master-controllers.service
  399. - /usr/local/bin/openshift
  400. - /usr/local/bin/oadm
  401. - /usr/local/bin/oc
  402. - /usr/local/bin/kubectl
  403. - /etc/flannel
  404. - name: Remove remaining OVS files
  405. file: path={{ item }} state=absent
  406. with_items:
  407. - /etc/systemd/system/openvswitch.service
  408. when: openshift_use_openshift_sdn | default(True) | bool
  409. # Since we are potentially removing the systemd unit files for separated
  410. # master-api and master-controllers services, so we need to reload the
  411. # systemd configuration manager
  412. - name: Reload systemd manager configuration
  413. command: systemctl daemon-reload
  414. - hosts: etcd
  415. become: yes
  416. vars:
  417. etcd_dirs:
  418. - "/etc/etcd"
  419. - "/var/lib/etcd"
  420. tasks:
  421. - name: unmask services
  422. command: systemctl unmask "{{ item }}"
  423. changed_when: False
  424. failed_when: False
  425. with_items:
  426. - etcd
  427. - etcd3
  428. - firewalld
  429. - name: Stop additional atomic services
  430. service: name={{ item }} state=stopped
  431. when: openshift_is_containerized | bool
  432. with_items:
  433. - etcd_container
  434. failed_when: false
  435. - name: Remove packages
  436. package: name={{ item }} state=absent
  437. when: not openshift_is_atomic | bool and openshift_remove_all | default(True) | bool
  438. with_items:
  439. - etcd
  440. - etcd3
  441. register: result
  442. until: result is succeeded
  443. - shell: systemctl reset-failed
  444. changed_when: False
  445. - shell: systemctl daemon-reload
  446. changed_when: False
  447. - find: path={{ item }} file_type=file
  448. register: files
  449. with_items:
  450. - "{{ etcd_dirs }}"
  451. - find: path={{ item }} file_type=directory
  452. register: directories
  453. with_items:
  454. - "{{ etcd_dirs }}"
  455. - file: path={{ item.1.path }} state=absent
  456. with_subelements:
  457. - "{{ files.results | default([]) }}"
  458. - files
  459. - file: path={{ item.1.path }} state=absent
  460. with_subelements:
  461. - "{{ directories.results | default([]) }}"
  462. - files
  463. # Intenationally using rm command over file module because if someone had mounted a filesystem
  464. # at /var/lib/etcd then the contents was not removed correctly
  465. - name: Remove etcd data
  466. shell: rm -rf /var/lib/etcd/*
  467. args:
  468. warn: no
  469. failed_when: false
  470. - name: Remove remaining files
  471. file: path={{ item }} state=absent
  472. with_items:
  473. - /etc/ansible/facts.d/openshift.fact
  474. - /etc/systemd/system/etcd_container.service
  475. - /etc/profile.d/etcdctl.sh
  476. - hosts: lb
  477. become: yes
  478. tasks:
  479. - name: unmask services
  480. command: systemctl unmask "{{ item }}"
  481. changed_when: False
  482. failed_when: False
  483. with_items:
  484. - firewalld
  485. - name: Remove packages
  486. package: name={{ item }} state=absent
  487. when: not openshift_is_atomic | bool and openshift_remove_all | default(True) | bool
  488. with_items:
  489. - haproxy
  490. register: result
  491. until: result is succeeded
  492. - shell: systemctl reset-failed
  493. changed_when: False
  494. - shell: systemctl daemon-reload
  495. changed_when: False
  496. - name: Remove remaining files
  497. file: path={{ item }} state=absent
  498. with_items:
  499. - /etc/ansible/facts.d/openshift.fact
  500. - /var/lib/haproxy/stats
  501. # Here we remove only limits.conf rather than directory, as users may put their files.
  502. # - /etc/systemd/system/haproxy.service.d
  503. - /etc/systemd/system/haproxy.service.d/limits.conf
  504. - /etc/systemd/system/haproxy.service