uninstall_openshift.yml 15 KB

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