upgrade.yml 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. ---
  2. ###############################################################################
  3. # Upgrade Masters
  4. ###############################################################################
  5. # Some change makes critical outage on current cluster.
  6. - name: Confirm upgrade will not make critical changes
  7. hosts: oo_first_master
  8. tasks:
  9. - name: Confirm Reconcile Security Context Constraints will not change current SCCs
  10. command: >
  11. {{ openshift_client_binary }} adm policy --config={{ openshift.common.config_base }}/master/admin.kubeconfig reconcile-sccs --additive-only=true -o name
  12. register: check_reconcile_scc_result
  13. when: openshift_reconcile_sccs_reject_change | default(true) | bool
  14. until: check_reconcile_scc_result.rc == 0
  15. retries: 3
  16. - fail:
  17. msg: >
  18. Changes to bootstrapped SCCs have been detected. Please review the changes by running
  19. "{{ openshift_client_binary }} adm policy --config={{ openshift.common.config_base }}/master/admin.kubeconfig reconcile-sccs --additive-only=true"
  20. After reviewing the changes please apply those changes by adding the '--confirm' flag.
  21. Do not modify the default SCCs. Customizing the default SCCs will cause this check to fail when upgrading.
  22. If you require non standard SCCs please refer to https://docs.openshift.org/latest/admin_guide/manage_scc.html
  23. when:
  24. - openshift_reconcile_sccs_reject_change | default(true) | bool
  25. - check_reconcile_scc_result.stdout != '' or check_reconcile_scc_result.rc != 0
  26. # Create service signer cert when missing. Service signer certificate
  27. # is added to master config in the master_config_upgrade hook.
  28. - name: Determine if service signer cert must be created
  29. hosts: oo_first_master
  30. tasks:
  31. - name: Determine if service signer certificate must be created
  32. stat:
  33. path: "{{ openshift.common.config_base }}/master/service-signer.crt"
  34. register: service_signer_cert_stat
  35. changed_when: false
  36. - name: verify api server
  37. command: >
  38. curl --silent --tlsv1.2
  39. --cacert {{ openshift.common.config_base }}/master/ca-bundle.crt
  40. {{ openshift.master.api_url }}/healthz/ready
  41. args:
  42. # Disables the following warning:
  43. # Consider using get_url or uri module rather than running curl
  44. warn: no
  45. register: api_available_output
  46. until: api_available_output.stdout == 'ok'
  47. retries: 120
  48. delay: 1
  49. changed_when: false
  50. - import_playbook: create_service_signer_cert.yml
  51. # oc adm migrate storage should be run prior to etcd v3 upgrade
  52. # See: https://github.com/openshift/origin/pull/14625#issuecomment-308467060
  53. - name: Pre master upgrade - Upgrade all storage
  54. hosts: oo_first_master
  55. roles:
  56. - openshift_facts
  57. tasks:
  58. - name: Upgrade all storage
  59. command: >
  60. {{ openshift_client_binary }} adm --config={{ openshift.common.config_base }}/master/admin.kubeconfig
  61. migrate storage --include=* --confirm
  62. register: l_pb_upgrade_control_plane_pre_upgrade_storage
  63. when: openshift_upgrade_pre_storage_migration_enabled | default(true) | bool
  64. failed_when:
  65. - l_pb_upgrade_control_plane_pre_upgrade_storage.rc != 0
  66. - openshift_upgrade_pre_storage_migration_fatal | default(true) | bool
  67. retries: 2
  68. delay: 30
  69. - name: Migrate legacy HPA scale target refs
  70. command: >
  71. {{ openshift_client_binary }} adm --config={{ openshift.common.config_base }}/master/admin.kubeconfig
  72. migrate legacy-hpa --confirm
  73. register: migrate_legacy_hpa_result
  74. when: openshift_upgrade_pre_storage_migration_enabled | default(true) | bool
  75. failed_when:
  76. - migrate_legacy_hpa_result.rc != 0
  77. - openshift_upgrade_pre_storage_migration_fatal | default(true) | bool
  78. # Set openshift_master_facts separately. In order to reconcile
  79. # admission_config's, we currently must run openshift_master_facts and
  80. # then run openshift_facts.
  81. - name: Set OpenShift master facts
  82. hosts: oo_masters_to_config
  83. roles:
  84. - openshift_master_facts
  85. - name: configure vsphere svc account
  86. hosts: oo_first_master
  87. tasks:
  88. - import_role:
  89. name: openshift_cloud_provider
  90. tasks_from: vsphere-svc.yml
  91. when:
  92. - openshift_cloudprovider_kind is defined
  93. - openshift_cloudprovider_kind == 'vsphere'
  94. # The main master upgrade play. Should handle all changes to the system in one pass, with
  95. # support for optional hooks to be defined.
  96. - name: Upgrade master
  97. hosts: oo_masters_to_config
  98. serial: 1
  99. roles:
  100. - openshift_facts
  101. tasks:
  102. # Run the pre-upgrade hook if defined:
  103. - debug: msg="Running master pre-upgrade hook {{ openshift_master_upgrade_pre_hook }}"
  104. when: openshift_master_upgrade_pre_hook is defined
  105. - include_tasks: "{{ openshift_master_upgrade_pre_hook }}"
  106. when: openshift_master_upgrade_pre_hook is defined
  107. - import_role:
  108. name: openshift_control_plane
  109. tasks_from: upgrade.yml
  110. - name: update vsphere provider master config
  111. import_role:
  112. name: openshift_cloud_provider
  113. tasks_from: update-vsphere.yml
  114. when:
  115. - openshift_cloudprovider_kind is defined
  116. - openshift_cloudprovider_kind == 'vsphere'
  117. # Run the upgrade hook prior to restarting services/system if defined:
  118. - debug: msg="Running master upgrade hook {{ openshift_master_upgrade_hook }}"
  119. when: openshift_master_upgrade_hook is defined
  120. - include_tasks: "{{ openshift_master_upgrade_hook }}"
  121. when: openshift_master_upgrade_hook is defined
  122. - name: Lay down the static configuration
  123. import_role:
  124. name: openshift_control_plane
  125. tasks_from: static.yml
  126. - import_tasks: tasks/restart_hosts.yml
  127. when: openshift_rolling_restart_mode | default('services') == 'system'
  128. - import_tasks: tasks/restart_services.yml
  129. when: openshift_rolling_restart_mode | default('services') == 'services'
  130. # Run the post-upgrade hook if defined:
  131. - debug: msg="Running master post-upgrade hook {{ openshift_master_upgrade_post_hook }}"
  132. when: openshift_master_upgrade_post_hook is defined
  133. - include_tasks: "{{ openshift_master_upgrade_post_hook }}"
  134. when: openshift_master_upgrade_post_hook is defined
  135. - set_fact:
  136. master_update_complete: True
  137. ##############################################################################
  138. # Gate on master update complete
  139. ##############################################################################
  140. - name: Gate on master update
  141. hosts: localhost
  142. connection: local
  143. tasks:
  144. - set_fact:
  145. master_update_completed: "{{ hostvars
  146. | lib_utils_oo_select_keys(groups.oo_masters_to_config)
  147. | lib_utils_oo_collect('inventory_hostname', {'master_update_complete': true}) }}"
  148. - set_fact:
  149. master_update_failed: "{{ groups.oo_masters_to_config | difference(master_update_completed) | list }}"
  150. - fail:
  151. msg: "Upgrade cannot continue. The following masters did not finish updating: {{ master_update_failed | join(',') }}"
  152. when: master_update_failed | length > 0
  153. ###############################################################################
  154. # Reconcile Cluster Roles, Cluster Role Bindings and Security Context Constraints
  155. ###############################################################################
  156. - name: Reconcile Cluster Roles and Cluster Role Bindings and Security Context Constraints
  157. hosts: oo_masters_to_config
  158. roles:
  159. - { role: openshift_cli }
  160. - { role: openshift_facts }
  161. vars:
  162. __master_shared_resource_viewer_file: "shared_resource_viewer_role.yaml"
  163. tasks:
  164. - name: Reconcile Security Context Constraints
  165. command: >
  166. {{ openshift_client_binary }} adm policy --config={{ openshift.common.config_base }}/master/admin.kubeconfig reconcile-sccs --confirm --additive-only=true -o name
  167. register: reconcile_scc_result
  168. changed_when:
  169. - reconcile_scc_result.stdout != ''
  170. - reconcile_scc_result.rc == 0
  171. run_once: true
  172. - name: Migrate storage post policy reconciliation
  173. command: >
  174. {{ openshift_client_binary }} adm --config={{ openshift.common.config_base }}/master/admin.kubeconfig
  175. migrate storage --include=* --confirm
  176. run_once: true
  177. register: l_pb_upgrade_control_plane_post_upgrade_storage
  178. when: openshift_upgrade_post_storage_migration_enabled | default(true) | bool
  179. failed_when:
  180. - l_pb_upgrade_control_plane_post_upgrade_storage.rc != 0
  181. - openshift_upgrade_post_storage_migration_fatal | default(false) | bool
  182. retries: 2
  183. delay: 30
  184. - set_fact:
  185. reconcile_complete: True
  186. ##############################################################################
  187. # Gate on reconcile
  188. ##############################################################################
  189. - name: Gate on reconcile
  190. hosts: localhost
  191. connection: local
  192. tasks:
  193. - set_fact:
  194. reconcile_completed: "{{ hostvars
  195. | lib_utils_oo_select_keys(groups.oo_masters_to_config)
  196. | lib_utils_oo_collect('inventory_hostname', {'reconcile_complete': true}) }}"
  197. - set_fact:
  198. reconcile_failed: "{{ groups.oo_masters_to_config | difference(reconcile_completed) | list }}"
  199. - fail:
  200. msg: "Upgrade cannot continue. The following masters did not finish reconciling: {{ reconcile_failed | join(',') }}"
  201. when: reconcile_failed | length > 0
  202. - name: Drain and upgrade master nodes
  203. hosts: oo_masters_to_config:&oo_nodes_to_upgrade
  204. # This var must be set with -e on invocation, as it is not a per-host inventory var
  205. # and is evaluated early. Values such as "20%" can also be used.
  206. serial: "{{ openshift_upgrade_control_plane_nodes_serial | default(1) }}"
  207. max_fail_percentage: "{{ openshift_upgrade_control_plane_nodes_max_fail_percentage | default(0) }}"
  208. pre_tasks:
  209. - name: Load lib_openshift modules
  210. import_role:
  211. name: lib_openshift
  212. roles:
  213. - openshift_facts
  214. post_tasks:
  215. - import_role:
  216. name: openshift_manage_node
  217. tasks_from: config.yml
  218. vars:
  219. openshift_master_host: "{{ groups.oo_first_master.0 }}"
  220. openshift_manage_node_is_master: true