pre.yml 12 KB

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