uninstall.yml 15 KB

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