pre.yml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. ---
  2. ###############################################################################
  3. # Evaluate host groups and gather facts
  4. ###############################################################################
  5. - include: ../initialize_facts.yml
  6. - name: Update repos and initialize facts on all hosts
  7. hosts: oo_masters_to_config:oo_nodes_to_config:oo_etcd_to_config:oo_lb_to_config
  8. roles:
  9. - openshift_repos
  10. - name: Set openshift_no_proxy_internal_hostnames
  11. hosts: oo_masters_to_config:oo_nodes_to_config
  12. tasks:
  13. - set_fact:
  14. openshift_no_proxy_internal_hostnames: "{{ hostvars | oo_select_keys(groups['oo_nodes_to_config']
  15. | union(groups['oo_masters_to_config'])
  16. | union(groups['oo_etcd_to_config'] | default([])))
  17. | oo_collect('openshift.common.hostname') | default([]) | join (',')
  18. }}"
  19. when: "{{ (openshift_http_proxy is defined or openshift_https_proxy is defined) and
  20. openshift_generate_no_proxy_hosts | default(True) | bool }}"
  21. - name: Evaluate additional groups for upgrade
  22. hosts: localhost
  23. connection: local
  24. become: no
  25. tasks:
  26. - name: Evaluate etcd_hosts_to_backup
  27. add_host:
  28. name: "{{ item }}"
  29. groups: etcd_hosts_to_backup
  30. 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
  31. ###############################################################################
  32. # Pre-upgrade checks
  33. ###############################################################################
  34. - name: Verify upgrade can proceed on first master
  35. hosts: oo_first_master
  36. vars:
  37. g_pacemaker_upgrade_url_segment: "{{ 'org/latest' if deployment_type =='origin' else '.com/enterprise/3.1' }}"
  38. gather_facts: no
  39. tasks:
  40. - fail:
  41. msg: >
  42. This upgrade is only supported for atomic-enterprise, origin, openshift-enterprise, and online
  43. deployment types
  44. when: deployment_type not in ['atomic-enterprise', 'origin','openshift-enterprise', 'online']
  45. - fail:
  46. msg: >
  47. This upgrade does not support Pacemaker:
  48. https://docs.openshift.{{ g_pacemaker_upgrade_url_segment }}/install_config/upgrading/pacemaker_to_native_ha.html
  49. when: openshift.master.cluster_method is defined and openshift.master.cluster_method == 'pacemaker'
  50. # Error out in situations where the user has older versions specified in their
  51. # inventory in any of the openshift_release, openshift_image_tag, and
  52. # openshift_pkg_version variables. These must be removed or updated to proceed
  53. # with upgrade.
  54. # TODO: Should we block if you're *over* the next major release version as well?
  55. - fail:
  56. msg: >
  57. openshift_pkg_version is {{ openshift_pkg_version }} which is not a
  58. valid version for a {{ openshift_upgrade_target }} upgrade
  59. when: openshift_pkg_version is defined and openshift_pkg_version.split('-',1).1 | version_compare(openshift_upgrade_target ,'<')
  60. - fail:
  61. msg: >
  62. openshift_image_tag is {{ openshift_image_tag }} which is not a
  63. valid version for a {{ openshift_upgrade_target }} upgrade
  64. when: openshift_image_tag is defined and openshift_image_tag.split('v',1).1 | version_compare(openshift_upgrade_target ,'<')
  65. - set_fact:
  66. openshift_release: "{{ openshift_release[1:] }}"
  67. when: openshift_release is defined and openshift_release[0] == 'v'
  68. - fail:
  69. msg: >
  70. openshift_release is {{ openshift_release }} which is not a
  71. valid release for a {{ openshift_upgrade_target }} upgrade
  72. when: openshift_release is defined and not openshift_release | version_compare(openshift_upgrade_target ,'=')
  73. - include: ../../../common/openshift-cluster/initialize_openshift_version.yml
  74. vars:
  75. # Request specific openshift_release and let the openshift_version role handle converting this
  76. # to a more specific version, respecting openshift_image_tag and openshift_pkg_version if
  77. # defined, and overriding the normal behavior of protecting the installed version
  78. openshift_release: "{{ openshift_upgrade_target }}"
  79. openshift_protect_installed_version: False
  80. # Docker role (a dependency) should be told not to do anything to installed version
  81. # of docker, we handle this separately during upgrade. (the inventory may have a
  82. # docker_version defined, we don't want to actually do it until later)
  83. docker_protect_installed_version: True
  84. - name: Verify master processes
  85. hosts: oo_masters_to_config
  86. roles:
  87. - openshift_facts
  88. tasks:
  89. - openshift_facts:
  90. role: master
  91. local_facts:
  92. ha: "{{ groups.oo_masters_to_config | length > 1 }}"
  93. - name: Ensure Master is running
  94. service:
  95. name: "{{ openshift.common.service_type }}-master"
  96. state: started
  97. enabled: yes
  98. when: openshift.master.ha is defined and not openshift.master.ha | bool and openshift.common.is_containerized | bool
  99. - name: Ensure HA Master is running
  100. service:
  101. name: "{{ openshift.common.service_type }}-master-api"
  102. state: started
  103. enabled: yes
  104. when: openshift.master.ha is defined and openshift.master.ha | bool and openshift.common.is_containerized | bool
  105. - name: Ensure HA Master is running
  106. service:
  107. name: "{{ openshift.common.service_type }}-master-controllers"
  108. state: started
  109. enabled: yes
  110. when: openshift.master.ha is defined and openshift.master.ha | bool and openshift.common.is_containerized | bool
  111. - name: Verify node processes
  112. hosts: oo_nodes_to_config
  113. roles:
  114. - openshift_facts
  115. - openshift_docker_facts
  116. tasks:
  117. - name: Ensure Node is running
  118. service:
  119. name: "{{ openshift.common.service_type }}-node"
  120. state: started
  121. enabled: yes
  122. when: openshift.common.is_containerized | bool
  123. - name: Verify upgrade targets
  124. hosts: oo_masters_to_config:oo_nodes_to_config
  125. vars:
  126. openshift_docker_hosted_registry_network: "{{ hostvars[groups.oo_first_master.0].openshift.common.portal_net }}"
  127. pre_tasks:
  128. - fail:
  129. msg: Verify OpenShift is already installed
  130. when: openshift.common.version is not defined
  131. - fail:
  132. msg: Verify the correct version was found
  133. when: verify_upgrade_version is defined and openshift_version != verify_upgrade_version
  134. - name: Clean package cache
  135. command: "{{ ansible_pkg_mgr }} clean all"
  136. when: not openshift.common.is_atomic | bool
  137. - set_fact:
  138. g_new_service_name: "{{ 'origin' if deployment_type =='origin' else 'atomic-openshift' }}"
  139. when: not openshift.common.is_containerized | bool
  140. - name: Verify containers are available for upgrade
  141. command: >
  142. docker pull {{ openshift.common.cli_image }}:{{ openshift_image_tag }}
  143. register: pull_result
  144. changed_when: "'Downloaded newer image' in pull_result.stdout"
  145. when: openshift.common.is_containerized | bool
  146. - name: Check latest available OpenShift RPM version
  147. command: >
  148. {{ repoquery_cmd }} --qf '%{version}' "{{ openshift.common.service_type }}"
  149. failed_when: false
  150. changed_when: false
  151. register: avail_openshift_version
  152. when: not openshift.common.is_containerized | bool
  153. - name: Verify OpenShift RPMs are available for upgrade
  154. fail:
  155. msg: "OpenShift {{ avail_openshift_version.stdout }} is available, but {{ openshift_upgrade_target }} or greater is required"
  156. when: not openshift.common.is_containerized | bool and not avail_openshift_version | skipped and avail_openshift_version.stdout | default('0.0', True) | version_compare(openshift_release, '<')
  157. - fail:
  158. msg: "This upgrade playbook must be run against OpenShift {{ openshift_upgrade_min }} or later"
  159. when: deployment_type == 'origin' and openshift.common.version | version_compare(openshift_upgrade_min,'<')
  160. - name: Verify docker upgrade targets
  161. hosts: oo_masters_to_config:oo_nodes_to_config:oo_etcd_to_config
  162. tasks:
  163. # Only check if docker upgrade is required if docker_upgrade is not
  164. # already set to False.
  165. - include: docker/upgrade_check.yml
  166. when: docker_upgrade is not defined or docker_upgrade | bool and not openshift.common.is_atomic | bool
  167. # Additional checks for Atomic hosts:
  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. l_docker_version: "{{ g_atomic_docker_version_result.stdout | from_yaml }}"
  174. when: openshift.common.is_atomic | bool
  175. - fail:
  176. msg: This playbook requires access to Docker 1.10 or later
  177. when: openshift.common.is_atomic | bool and l_docker_version.avail_version | default(l_docker_version.curr_version, true) | version_compare('1.10','<')
  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: "{{ hostvars[groups.oo_first_master.0].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
  267. - name: Exit upgrade if dry-run specified
  268. hosts: oo_first_master
  269. tasks:
  270. - fail:
  271. msg: "Pre-upgrade checks completed, exiting due to openshift_upgrade_dry_run variable."
  272. when: openshift_upgrade_dry_run is defined and openshift_upgrade_dry_run | bool