uninstall.yml 15 KB

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