uninstall.yml 15 KB

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