uninstall.yml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. # This deletes *ALL* Origin, Atomic Enterprise Platform and OpenShift
  2. # Enterprise content installed by 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. is_atomic: "{{ ostree_output.rc == 0 }}"
  21. - set_fact:
  22. is_containerized: "{{ is_atomic or containerized | default(false) | bool }}"
  23. # Stop services on all hosts prior to removing files.
  24. - hosts: nodes
  25. become: yes
  26. tasks:
  27. - name: Remove dnsmasq dispatcher
  28. file:
  29. path: "{{ item }}"
  30. state: absent
  31. with_items:
  32. - /etc/dnsmasq.d/origin-dns.conf
  33. - /etc/dnsmasq.d/origin-upstream-dns.conf
  34. - /etc/dnsmasq.d/openshift-ansible.conf
  35. - /etc/NetworkManager/dispatcher.d/99-origin-dns.sh
  36. when: openshift_use_dnsmasq | default(true) | bool
  37. - service:
  38. name: NetworkManager
  39. state: restarted
  40. when: openshift_use_dnsmasq | default(true) | bool
  41. - name: Stop services
  42. service: name={{ item }} state=stopped
  43. with_items:
  44. - atomic-enterprise-node
  45. - atomic-openshift-node
  46. - openshift-node
  47. - openvswitch
  48. - origin-node
  49. failed_when: false
  50. - hosts: masters
  51. become: yes
  52. tasks:
  53. - name: Stop services
  54. service: name={{ item }} state=stopped
  55. with_items:
  56. - atomic-enterprise-master
  57. - atomic-openshift-master
  58. - atomic-openshift-master-api
  59. - atomic-openshift-master-controllers
  60. - openshift-master
  61. - openshift-master-api
  62. - openshift-master-controllers
  63. - origin-master
  64. - origin-master-api
  65. - origin-master-controllers
  66. - pcsd
  67. failed_when: false
  68. - hosts: etcd
  69. become: yes
  70. tasks:
  71. - name: Stop services
  72. service: name={{ item }} state=stopped
  73. with_items:
  74. - etcd
  75. failed_when: false
  76. - hosts: lb
  77. become: yes
  78. tasks:
  79. - name: Stop services
  80. service: name={{ item }} state=stopped
  81. with_items:
  82. - haproxy
  83. failed_when: false
  84. - hosts: nodes
  85. become: yes
  86. vars:
  87. node_dirs:
  88. - "/etc/origin"
  89. - "/var/lib/origin"
  90. tasks:
  91. - name: unmask services
  92. command: systemctl unmask "{{ item }}"
  93. changed_when: False
  94. failed_when: False
  95. with_items:
  96. - firewalld
  97. - block:
  98. - block:
  99. - name: Remove packages
  100. package: name={{ item }} state=absent
  101. with_items:
  102. - atomic-enterprise
  103. - atomic-enterprise-node
  104. - atomic-enterprise-sdn-ovs
  105. - atomic-openshift
  106. - atomic-openshift-clients
  107. - atomic-openshift-excluder
  108. - atomic-openshift-docker-excluder
  109. - atomic-openshift-node
  110. - atomic-openshift-sdn-ovs
  111. - cockpit-bridge
  112. - cockpit-docker
  113. - cockpit-system
  114. - cockpit-ws
  115. - kubernetes-client
  116. - openshift
  117. - openshift-node
  118. - openshift-sdn
  119. - openshift-sdn-ovs
  120. - openvswitch
  121. - origin
  122. - origin-excluder
  123. - origin-docker-excluder
  124. - origin-clients
  125. - origin-node
  126. - origin-sdn-ovs
  127. - tuned-profiles-atomic-enterprise-node
  128. - tuned-profiles-atomic-openshift-node
  129. - tuned-profiles-openshift-node
  130. - tuned-profiles-origin-node
  131. - name: Remove flannel package
  132. package: name=flannel state=absent
  133. when: openshift_use_flannel | default(false) | bool
  134. when: not 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. - name: Remove linux interfaces
  144. shell: ip link del "{{ item }}"
  145. changed_when: False
  146. failed_when: False
  147. with_items:
  148. - lbr0
  149. - vlinuxbr
  150. - vovsbr
  151. when: openshift_remove_all | default(true) | bool
  152. - shell: atomic uninstall "{{ item }}"-master-api
  153. changed_when: False
  154. failed_when: False
  155. with_items:
  156. - openshift-enterprise
  157. - atomic-enterprise
  158. - origin
  159. - shell: atomic uninstall "{{ item }}"-master-controllers
  160. changed_when: False
  161. failed_when: False
  162. with_items:
  163. - openshift-enterprise
  164. - atomic-enterprise
  165. - origin
  166. - shell: atomic uninstall "{{ item }}"-master
  167. changed_when: False
  168. failed_when: False
  169. with_items:
  170. - openshift-enterprise
  171. - atomic-enterprise
  172. - origin
  173. - shell: atomic uninstall "{{ item }}"-node
  174. changed_when: False
  175. failed_when: False
  176. with_items:
  177. - openshift-enterprise
  178. - atomic-enterprise
  179. - origin
  180. - shell: atomic uninstall "{{ item }}"
  181. changed_when: False
  182. failed_when: False
  183. with_items:
  184. - etcd
  185. - openvswitch
  186. - shell: find /var/lib/origin/openshift.local.volumes -type d -exec umount {} \; 2>/dev/null || true
  187. changed_when: False
  188. - shell: find /var/lib/atomic-enterprise/openshift.local.volumes -type d -exec umount {} \; 2>/dev/null || true
  189. changed_when: False
  190. - shell: find /var/lib/openshift/openshift.local.volumes -type d -exec umount {} \; 2>/dev/null || true
  191. changed_when: False
  192. - shell: docker rm -f "{{ item }}"-master "{{ item }}"-node
  193. changed_when: False
  194. failed_when: False
  195. with_items:
  196. - openshift-enterprise
  197. - atomic-enterprise
  198. - origin
  199. - shell: docker ps -a | grep Exited | egrep "{{ item }}" | awk '{print $1}'
  200. changed_when: False
  201. failed_when: False
  202. register: exited_containers_to_delete
  203. with_items:
  204. - aep3.*/aep
  205. - aep3.*/node
  206. - aep3.*/openvswitch
  207. - openshift3/ose
  208. - openshift3/node
  209. - openshift3/openvswitch
  210. - openshift/origin
  211. - shell: "docker rm {{ item.stdout_lines | join(' ') }}"
  212. changed_when: False
  213. failed_when: False
  214. with_items: "{{ exited_containers_to_delete.results }}"
  215. - block:
  216. - block:
  217. - shell: docker images | egrep {{ item }} | awk '{ print $3 }'
  218. changed_when: False
  219. failed_when: False
  220. register: images_to_delete
  221. with_items:
  222. - registry\.access\..*redhat\.com/openshift3
  223. - registry\.access\..*redhat\.com/aep3
  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. - /etc/sysconfig/openvswitch
  241. - /run/openshift-sdn
  242. when: openshift_remove_all | default(True) | bool
  243. - find: path={{ item }} file_type=file
  244. register: files
  245. with_items:
  246. - "{{ node_dirs }}"
  247. - find: path={{ item }} file_type=directory
  248. register: directories
  249. with_items:
  250. - "{{ node_dirs }}"
  251. - file: path={{ item.1.path }} state=absent
  252. with_subelements:
  253. - "{{ files.results | default([]) }}"
  254. - files
  255. - file: path={{ item.1.path }} state=absent
  256. with_subelements:
  257. - "{{ directories.results | default([]) }}"
  258. - files
  259. - name: Remove remaining files
  260. file: path={{ item }} state=absent
  261. with_items:
  262. - /etc/ansible/facts.d/openshift.fact
  263. - /etc/atomic-enterprise
  264. - /etc/openshift
  265. - /etc/openshift-sdn
  266. - /etc/sysconfig/atomic-enterprise-node
  267. - /etc/sysconfig/atomic-openshift-node
  268. - /etc/sysconfig/atomic-openshift-node-dep
  269. - /etc/sysconfig/openshift-node-dep
  270. - /etc/sysconfig/origin-node
  271. - /etc/sysconfig/origin-node
  272. - /etc/sysconfig/origin-node-dep
  273. - /etc/systemd/system/atomic-openshift-node-dep.service
  274. - /etc/systemd/system/atomic-openshift-node.service
  275. - /etc/systemd/system/atomic-openshift-node.service.wants
  276. - /etc/systemd/system/docker.service.d/docker-sdn-ovs.conf
  277. - /etc/systemd/system/openvswitch.service
  278. - /etc/systemd/system/origin-node-dep.service
  279. - /etc/systemd/system/origin-node.service
  280. - /etc/systemd/system/origin-node.service.wants
  281. - /var/lib/atomic-enterprise
  282. - /var/lib/openshift
  283. - shell: systemctl daemon-reload
  284. changed_when: False
  285. - name: restart container-engine
  286. service: name=container-engine state=restarted
  287. failed_when: false
  288. register: container_engine
  289. - name: restart docker
  290. service: name=docker state=restarted
  291. failed_when: false
  292. when: not (container_engine | changed)
  293. - hosts: masters
  294. become: yes
  295. vars:
  296. master_dirs:
  297. - "/etc/origin"
  298. - "/var/lib/origin"
  299. tasks:
  300. - name: unmask services
  301. command: systemctl unmask "{{ item }}"
  302. changed_when: False
  303. failed_when: False
  304. with_items:
  305. - firewalld
  306. - atomic-openshift-master
  307. - name: Remove packages
  308. package: name={{ item }} state=absent
  309. when: not is_atomic | bool and openshift_remove_all | default(True) | bool
  310. with_items:
  311. - atomic-enterprise
  312. - atomic-enterprise-master
  313. - atomic-openshift
  314. - atomic-openshift-clients
  315. - atomic-openshift-excluder
  316. - atomic-openshift-docker-excluder
  317. - atomic-openshift-master
  318. - cockpit-bridge
  319. - cockpit-docker
  320. - cockpit-system
  321. - cockpit-ws
  322. - corosync
  323. - kubernetes-client
  324. - openshift
  325. - openshift-master
  326. - origin
  327. - origin-clients
  328. - origin-excluder
  329. - origin-docker-excluder
  330. - origin-master
  331. - pacemaker
  332. - pcs
  333. - shell: systemctl reset-failed
  334. changed_when: False
  335. - shell: systemctl daemon-reload
  336. changed_when: False
  337. - name: Remove files owned by RPMs
  338. file: path={{ item }} state=absent
  339. when: openshift_remove_all | default(True) | bool
  340. with_items:
  341. - /etc/sysconfig/atomic-openshift-master
  342. - /etc/sysconfig/openvswitch
  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/atomic-enterprise
  372. - /etc/corosync
  373. - /etc/openshift
  374. - /etc/openshift-sdn
  375. - /etc/systemd/system/atomic-openshift-master.service
  376. - /etc/systemd/system/atomic-openshift-master-api.service
  377. - /etc/systemd/system/atomic-openshift-master-controllers.service
  378. - /etc/systemd/system/origin-master.service
  379. - /etc/systemd/system/origin-master-api.service
  380. - /etc/systemd/system/origin-master-controllers.service
  381. - /etc/systemd/system/openvswitch.service
  382. - /etc/sysconfig/atomic-enterprise-master
  383. - /etc/sysconfig/atomic-enterprise-master-api
  384. - /etc/sysconfig/atomic-enterprise-master-controllers
  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. - /var/lib/atomic-enterprise
  396. - /var/lib/openshift
  397. - /var/lib/pacemaker
  398. - /var/lib/pcsd
  399. - /usr/lib/systemd/system/atomic-openshift-master-api.service
  400. - /usr/lib/systemd/system/atomic-openshift-master-controllers.service
  401. - /usr/lib/systemd/system/origin-master-api.service
  402. - /usr/lib/systemd/system/origin-master-controllers.service
  403. - /usr/local/bin/openshift
  404. - /usr/local/bin/oadm
  405. - /usr/local/bin/oc
  406. - /usr/local/bin/kubectl
  407. - /etc/flannel
  408. # Since we are potentially removing the systemd unit files for separated
  409. # master-api and master-controllers services, so we need to reload the
  410. # systemd configuration manager
  411. - name: Reload systemd manager configuration
  412. command: systemctl daemon-reload
  413. - hosts: etcd
  414. become: yes
  415. vars:
  416. etcd_dirs:
  417. - "/etc/etcd"
  418. - "/var/lib/etcd"
  419. tasks:
  420. - name: unmask services
  421. command: systemctl unmask "{{ item }}"
  422. changed_when: False
  423. failed_when: False
  424. with_items:
  425. - etcd
  426. - etcd3
  427. - firewalld
  428. - name: Stop additional atomic services
  429. service: name={{ item }} state=stopped
  430. when: is_containerized | bool
  431. with_items:
  432. - etcd_container
  433. failed_when: false
  434. - name: Remove packages
  435. package: name={{ item }} state=absent
  436. when: not is_atomic | bool and openshift_remove_all | default(True) | bool
  437. with_items:
  438. - etcd
  439. - etcd3
  440. - shell: systemctl reset-failed
  441. changed_when: False
  442. - shell: systemctl daemon-reload
  443. changed_when: False
  444. - find: path={{ item }} file_type=file
  445. register: files
  446. with_items:
  447. - "{{ etcd_dirs }}"
  448. - find: path={{ item }} file_type=directory
  449. register: directories
  450. with_items:
  451. - "{{ etcd_dirs }}"
  452. - file: path={{ item.1.path }} state=absent
  453. with_subelements:
  454. - "{{ files.results | default([]) }}"
  455. - files
  456. - file: path={{ item.1.path }} state=absent
  457. with_subelements:
  458. - "{{ directories.results | default([]) }}"
  459. - files
  460. # Intenationally using rm command over file module because if someone had mounted a filesystem
  461. # at /var/lib/etcd then the contents was not removed correctly
  462. - name: Remove etcd data
  463. shell: rm -rf /var/lib/etcd/*
  464. args:
  465. warn: no
  466. failed_when: false
  467. - name: Remove remaining files
  468. file: path={{ item }} state=absent
  469. with_items:
  470. - /etc/ansible/facts.d/openshift.fact
  471. - /etc/systemd/system/etcd_container.service
  472. - /etc/profile.d/etcdctl.sh
  473. - hosts: lb
  474. become: yes
  475. tasks:
  476. - name: unmask services
  477. command: systemctl unmask "{{ item }}"
  478. changed_when: False
  479. failed_when: False
  480. with_items:
  481. - firewalld
  482. - name: Remove packages
  483. package: name={{ item }} state=absent
  484. when: not is_atomic | bool and openshift_remove_all | default(True) | bool
  485. with_items:
  486. - haproxy
  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