uninstall.yml 15 KB

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