uninstall.yml 14 KB

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