upgrade.yml 9.3 KB

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