pre.yml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. ---
  2. ###############################################################################
  3. # Evaluate host groups and gather facts
  4. ###############################################################################
  5. - name: Load openshift_facts
  6. hosts: oo_masters_to_config:oo_nodes_to_config:oo_etcd_to_config:oo_lb_to_config
  7. roles:
  8. - openshift_facts
  9. - name: Evaluate additional groups for upgrade
  10. hosts: localhost
  11. connection: local
  12. become: no
  13. tasks:
  14. - name: Evaluate etcd_hosts_to_backup
  15. add_host:
  16. name: "{{ item }}"
  17. groups: etcd_hosts_to_backup
  18. with_items: groups.oo_etcd_to_config if groups.oo_etcd_to_config is defined and groups.oo_etcd_to_config | length > 0 else groups.oo_first_master
  19. ###############################################################################
  20. # Pre-upgrade checks
  21. ###############################################################################
  22. - name: Verify upgrade can proceed
  23. hosts: oo_first_master
  24. vars:
  25. target_version: "{{ '1.2' if deployment_type == 'origin' else '3.1.1.900' }}"
  26. gather_facts: no
  27. tasks:
  28. - fail:
  29. msg: >
  30. This upgrade is only supported for atomic-enterprise, origin, openshift-enterprise, and online
  31. deployment types
  32. when: deployment_type not in ['atomic-enterprise', 'origin','openshift-enterprise', 'online']
  33. - fail:
  34. msg: >
  35. openshift_pkg_version is {{ openshift_pkg_version }} which is not a
  36. valid version for a {{ target_version }} upgrade
  37. when: openshift_pkg_version is defined and openshift_pkg_version.split('-',1).1 | version_compare(target_version ,'<')
  38. - fail:
  39. msg: >
  40. openshift_image_tag is {{ openshift_image_tag }} which is not a
  41. valid version for a {{ target_version }} upgrade
  42. when: openshift_image_tag is defined and openshift_image_tag.split('v',1).1 | version_compare(target_version ,'<')
  43. - name: Verify upgrade can proceed
  44. hosts: oo_masters_to_config
  45. roles:
  46. - openshift_facts
  47. tasks:
  48. - name: Ensure Master is running
  49. service:
  50. name: "{{ openshift.common.service_type }}-master"
  51. state: started
  52. enabled: yes
  53. when: openshift.master.ha is defined and not openshift.master.ha | bool and openshift.common.is_containerized | bool
  54. - name: Ensure HA Master is running
  55. service:
  56. name: "{{ openshift.common.service_type }}-master-api"
  57. state: started
  58. enabled: yes
  59. when: openshift.master.ha is defined and openshift.master.ha | bool and openshift.common.is_containerized | bool
  60. - name: Ensure HA Master is running
  61. service:
  62. name: "{{ openshift.common.service_type }}-master-controllers"
  63. state: started
  64. enabled: yes
  65. when: openshift.master.ha is defined and openshift.master.ha | bool and openshift.common.is_containerized | bool
  66. post_tasks:
  67. - openshift_facts:
  68. role: master
  69. local_facts:
  70. ha: "{{ groups.oo_masters_to_config | length > 1 }}"
  71. - name: Verify upgrade can proceed
  72. hosts: oo_nodes_to_config
  73. roles:
  74. - openshift_facts
  75. tasks:
  76. - name: Ensure Node is running
  77. service:
  78. name: "{{ openshift.common.service_type }}-node"
  79. state: started
  80. enabled: yes
  81. when: openshift.common.is_containerized | bool
  82. - name: Verify upgrade can proceed
  83. hosts: oo_masters_to_config:oo_nodes_to_config
  84. vars:
  85. target_version: "{{ '1.2' if deployment_type == 'origin' else '3.1.1.900' }}"
  86. openshift_docker_hosted_registry_insecure: True
  87. openshift_docker_hosted_registry_network: "{{ hostvars[groups.oo_first_master.0].openshift.master.portal_net }}"
  88. handlers:
  89. - include: ../../../../../roles/openshift_master/handlers/main.yml
  90. - include: ../../../../../roles/openshift_node/handlers/main.yml
  91. roles:
  92. - openshift_cli
  93. tasks:
  94. - name: Clean package cache
  95. command: "{{ ansible_pkg_mgr }} clean all"
  96. when: not openshift.common.is_atomic | bool
  97. - set_fact:
  98. g_new_service_name: "{{ 'origin' if deployment_type =='origin' else 'atomic-openshift' }}"
  99. when: not openshift.common.is_containerized | bool
  100. - name: Determine available versions
  101. script: ../files/rpm_versions.sh {{ g_new_service_name }}
  102. register: g_rpm_versions_result
  103. when: not openshift.common.is_containerized | bool
  104. - set_fact:
  105. g_aos_versions: "{{ g_rpm_versions_result.stdout | from_yaml }}"
  106. when: not openshift.common.is_containerized | bool
  107. - name: Determine available versions
  108. script: ../files/openshift_container_versions.sh {{ openshift.common.service_type }}
  109. register: g_containerized_versions_result
  110. when: openshift.common.is_containerized | bool
  111. - set_fact:
  112. g_aos_versions: "{{ g_containerized_versions_result.stdout | from_yaml }}"
  113. when: openshift.common.is_containerized | bool
  114. - set_fact:
  115. g_new_version: "{{ g_aos_versions.curr_version.split('-', 1).0 if g_aos_versions.avail_version is none else g_aos_versions.avail_version.split('-', 1).0 }}"
  116. when: openshift_pkg_version is not defined
  117. - set_fact:
  118. g_new_version: "{{ openshift_pkg_version | replace('-','') }}"
  119. when: openshift_pkg_version is defined
  120. - set_fact:
  121. g_new_version: "{{ openshift_image_tag | replace('v','') }}"
  122. when: openshift_image_tag is defined
  123. - fail:
  124. msg: Verifying the correct version was found
  125. when: verify_upgrade_version is defined and g_new_version != verify_upgrade_version
  126. - include_vars: ../../../../../roles/openshift_master/vars/main.yml
  127. when: inventory_hostname in groups.oo_masters_to_config
  128. - name: Update systemd units
  129. include: ../../../../../roles/openshift_master/tasks/systemd_units.yml openshift_version=v{{ g_aos_versions.curr_version }}
  130. when: inventory_hostname in groups.oo_masters_to_config
  131. - include_vars: ../../../../../roles/openshift_node/vars/main.yml
  132. when: inventory_hostname in groups.oo_nodes_to_config
  133. - name: Update systemd units
  134. include: ../../../../../roles/openshift_node/tasks/systemd_units.yml openshift_version=v{{g_aos_versions.curr_version}}
  135. when: inventory_hostname in groups.oo_nodes_to_config
  136. # Note: the version number is hardcoded here in hopes of catching potential
  137. # bugs in how g_aos_versions.curr_version is set
  138. - name: Verifying the correct version is installed for upgrade
  139. shell: grep 3.1.1.6 {{ item }}
  140. with_items:
  141. - /etc/sysconfig/openvswitch
  142. - /etc/sysconfig/{{ openshift.common.service_type }}*
  143. when: verify_upgrade_version is defined
  144. - name: Verifying the image version is used in the systemd unit
  145. shell: grep IMAGE_VERSION {{ item }}
  146. with_items:
  147. - /etc/systemd/system/openvswitch.service
  148. - /etc/systemd/system/{{ openshift.common.service_type }}*.service
  149. when: openshift.common.is_containerized | bool
  150. - fail:
  151. msg: This playbook requires Origin 1.1 or later
  152. when: deployment_type == 'origin' and g_aos_versions.curr_version | version_compare('1.1','<')
  153. - fail:
  154. msg: This playbook requires Atomic Enterprise Platform/OpenShift Enterprise 3.1 or later
  155. when: deployment_type == 'atomic-openshift' and g_aos_versions.curr_version | version_compare('3.1','<')
  156. - fail:
  157. msg: Upgrade packages not found
  158. when: openshift_image_tag is not defined and (g_aos_versions.avail_version | default(g_aos_versions.curr_version, true) | version_compare(target_version, '<'))
  159. - name: Determine available Docker
  160. script: ../files/rpm_versions.sh docker
  161. register: g_docker_version_result
  162. when: not openshift.common.is_atomic | bool
  163. - name: Determine available Docker
  164. shell: "rpm -q --queryformat '---\ncurr_version: %{VERSION}\navail_version: \n' docker"
  165. register: g_atomic_docker_version_result
  166. when: openshift.common.is_atomic | bool
  167. - set_fact:
  168. g_docker_version: "{{ g_docker_version_result.stdout | from_yaml }}"
  169. when: not openshift.common.is_atomic | bool
  170. - set_fact:
  171. g_docker_version: "{{ g_atomic_docker_version_result.stdout | from_yaml }}"
  172. when: openshift.common.is_atomic | bool
  173. - fail:
  174. msg: This playbook requires access to Docker 1.9 or later
  175. when: not openshift.common.is_atomic | bool
  176. and (g_docker_version.avail_version | default(g_docker_version.curr_version, true) | version_compare('1.9','<'))
  177. # TODO: add check to upgrade ostree to get latest Docker
  178. - set_fact:
  179. pre_upgrade_complete: True
  180. ##############################################################################
  181. # Gate on pre-upgrade checks
  182. ##############################################################################
  183. - name: Gate on pre-upgrade checks
  184. hosts: localhost
  185. connection: local
  186. become: no
  187. vars:
  188. pre_upgrade_hosts: "{{ groups.oo_masters_to_config | union(groups.oo_nodes_to_config) }}"
  189. tasks:
  190. - set_fact:
  191. pre_upgrade_completed: "{{ hostvars
  192. | oo_select_keys(pre_upgrade_hosts)
  193. | oo_collect('inventory_hostname', {'pre_upgrade_complete': true}) }}"
  194. - set_fact:
  195. pre_upgrade_failed: "{{ pre_upgrade_hosts | difference(pre_upgrade_completed) }}"
  196. - fail:
  197. msg: "Upgrade cannot continue. The following hosts did not complete pre-upgrade checks: {{ pre_upgrade_failed | join(',') }}"
  198. when: pre_upgrade_failed | length > 0
  199. ###############################################################################
  200. # Backup etcd
  201. ###############################################################################
  202. - name: Backup etcd
  203. hosts: etcd_hosts_to_backup
  204. vars:
  205. embedded_etcd: "{{ openshift.master.embedded_etcd }}"
  206. timestamp: "{{ lookup('pipe', 'date +%Y%m%d%H%M%S') }}"
  207. roles:
  208. - openshift_facts
  209. tasks:
  210. # Ensure we persist the etcd role for this host in openshift_facts
  211. - openshift_facts:
  212. role: etcd
  213. local_facts: {}
  214. when: "'etcd' not in openshift"
  215. - stat: path=/var/lib/openshift
  216. register: var_lib_openshift
  217. - stat: path=/var/lib/origin
  218. register: var_lib_origin
  219. - name: Create origin symlink if necessary
  220. file: src=/var/lib/openshift/ dest=/var/lib/origin state=link
  221. when: var_lib_openshift.stat.exists == True and var_lib_origin.stat.exists == False
  222. # TODO: replace shell module with command and update later checks
  223. # We assume to be using the data dir for all backups.
  224. - name: Check available disk space for etcd backup
  225. shell: df --output=avail -k {{ openshift.common.data_dir }} | tail -n 1
  226. register: avail_disk
  227. # TODO: replace shell module with command and update later checks
  228. - name: Check current embedded etcd disk usage
  229. shell: du -k {{ openshift.etcd.etcd_data_dir }} | tail -n 1 | cut -f1
  230. register: etcd_disk_usage
  231. when: embedded_etcd | bool
  232. - name: Abort if insufficient disk space for etcd backup
  233. fail:
  234. msg: >
  235. {{ etcd_disk_usage.stdout }} Kb disk space required for etcd backup,
  236. {{ avail_disk.stdout }} Kb available.
  237. when: (embedded_etcd | bool) and (etcd_disk_usage.stdout|int > avail_disk.stdout|int)
  238. - name: Install etcd (for etcdctl)
  239. action: "{{ ansible_pkg_mgr }} name=etcd state=latest"
  240. when: not openshift.common.is_atomic | bool
  241. - name: Generate etcd backup
  242. command: >
  243. etcdctl backup --data-dir={{ openshift.etcd.etcd_data_dir }}
  244. --backup-dir={{ openshift.common.data_dir }}/etcd-backup-{{ timestamp }}
  245. - set_fact:
  246. etcd_backup_complete: True
  247. - name: Display location of etcd backup
  248. debug:
  249. msg: "Etcd backup created in {{ openshift.common.data_dir }}/etcd-backup-{{ timestamp }}"
  250. ##############################################################################
  251. # Gate on etcd backup
  252. ##############################################################################
  253. - name: Gate on etcd backup
  254. hosts: localhost
  255. connection: local
  256. become: no
  257. tasks:
  258. - set_fact:
  259. etcd_backup_completed: "{{ hostvars
  260. | oo_select_keys(groups.etcd_hosts_to_backup)
  261. | oo_collect('inventory_hostname', {'etcd_backup_complete': true}) }}"
  262. - set_fact:
  263. etcd_backup_failed: "{{ groups.etcd_hosts_to_backup | difference(etcd_backup_completed) }}"
  264. - fail:
  265. msg: "Upgrade cannot continue. The following hosts did not complete etcd backup: {{ etcd_backup_failed | join(',') }}"
  266. when: etcd_backup_failed | length > 0