upgrade.yml 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. retries: 2
  66. delay: 30
  67. # Set openshift_master_facts separately. In order to reconcile
  68. # admission_config's, we currently must run openshift_master_facts and
  69. # then run openshift_facts.
  70. - name: Set OpenShift master facts
  71. hosts: oo_masters_to_config
  72. roles:
  73. - openshift_master_facts
  74. - name: configure vsphere svc account
  75. hosts: oo_first_master
  76. tasks:
  77. - import_role:
  78. name: openshift_cloud_provider
  79. tasks_from: vsphere-svc
  80. when:
  81. - openshift_cloudprovider_kind is defined
  82. - openshift_cloudprovider_kind == 'vsphere'
  83. # The main master upgrade play. Should handle all changes to the system in one pass, with
  84. # support for optional hooks to be defined.
  85. - name: Upgrade master
  86. hosts: oo_masters_to_config
  87. serial: 1
  88. roles:
  89. - openshift_facts
  90. tasks:
  91. # Run the pre-upgrade hook if defined:
  92. - debug: msg="Running master pre-upgrade hook {{ openshift_master_upgrade_pre_hook }}"
  93. when: openshift_master_upgrade_pre_hook is defined
  94. - include_tasks: "{{ openshift_master_upgrade_pre_hook }}"
  95. when: openshift_master_upgrade_pre_hook is defined
  96. - import_role:
  97. name: openshift_control_plane
  98. tasks_from: upgrade
  99. - name: update vsphere provider master config
  100. import_role:
  101. name: openshift_cloud_provider
  102. tasks_from: update-vsphere
  103. when:
  104. - openshift_cloudprovider_kind is defined
  105. - openshift_cloudprovider_kind == 'vsphere'
  106. # Run the upgrade hook prior to restarting services/system if defined:
  107. - debug: msg="Running master upgrade hook {{ openshift_master_upgrade_hook }}"
  108. when: openshift_master_upgrade_hook is defined
  109. - include_tasks: "{{ openshift_master_upgrade_hook }}"
  110. when: openshift_master_upgrade_hook is defined
  111. - name: Lay down the static configuration
  112. import_role:
  113. name: openshift_control_plane
  114. tasks_from: static.yml
  115. - import_tasks: tasks/restart_hosts.yml
  116. when: openshift_rolling_restart_mode | default('services') == 'system'
  117. - import_tasks: tasks/restart_services.yml
  118. when: openshift_rolling_restart_mode | default('services') == 'services'
  119. # Run the post-upgrade hook if defined:
  120. - debug: msg="Running master post-upgrade hook {{ openshift_master_upgrade_post_hook }}"
  121. when: openshift_master_upgrade_post_hook is defined
  122. - include_tasks: "{{ openshift_master_upgrade_post_hook }}"
  123. when: openshift_master_upgrade_post_hook is defined
  124. - set_fact:
  125. master_update_complete: True
  126. ##############################################################################
  127. # Gate on master update complete
  128. ##############################################################################
  129. - name: Gate on master update
  130. hosts: localhost
  131. connection: local
  132. tasks:
  133. - set_fact:
  134. master_update_completed: "{{ hostvars
  135. | lib_utils_oo_select_keys(groups.oo_masters_to_config)
  136. | lib_utils_oo_collect('inventory_hostname', {'master_update_complete': true}) }}"
  137. - set_fact:
  138. master_update_failed: "{{ groups.oo_masters_to_config | difference(master_update_completed) | list }}"
  139. - fail:
  140. msg: "Upgrade cannot continue. The following masters did not finish updating: {{ master_update_failed | join(',') }}"
  141. when: master_update_failed | length > 0
  142. ###############################################################################
  143. # Reconcile Cluster Roles, Cluster Role Bindings and Security Context Constraints
  144. ###############################################################################
  145. - name: Reconcile Cluster Roles and Cluster Role Bindings and Security Context Constraints
  146. hosts: oo_masters_to_config
  147. roles:
  148. - { role: openshift_cli }
  149. - { role: openshift_facts }
  150. vars:
  151. __master_shared_resource_viewer_file: "shared_resource_viewer_role.yaml"
  152. tasks:
  153. - name: Reconcile Security Context Constraints
  154. command: >
  155. {{ openshift_client_binary }} adm policy --config={{ openshift.common.config_base }}/master/admin.kubeconfig reconcile-sccs --confirm --additive-only=true -o name
  156. register: reconcile_scc_result
  157. changed_when:
  158. - reconcile_scc_result.stdout != ''
  159. - reconcile_scc_result.rc == 0
  160. run_once: true
  161. - name: Migrate storage post policy reconciliation
  162. command: >
  163. {{ openshift_client_binary }} adm --config={{ openshift.common.config_base }}/master/admin.kubeconfig
  164. migrate storage --include=* --confirm
  165. run_once: true
  166. register: l_pb_upgrade_control_plane_post_upgrade_storage
  167. when: openshift_upgrade_post_storage_migration_enabled | default(true) | bool
  168. failed_when:
  169. - l_pb_upgrade_control_plane_post_upgrade_storage.rc != 0
  170. - openshift_upgrade_post_storage_migration_fatal | default(false) | bool
  171. retries: 2
  172. delay: 30
  173. - set_fact:
  174. reconcile_complete: True
  175. ##############################################################################
  176. # Gate on reconcile
  177. ##############################################################################
  178. - name: Gate on reconcile
  179. hosts: localhost
  180. connection: local
  181. tasks:
  182. - set_fact:
  183. reconcile_completed: "{{ hostvars
  184. | lib_utils_oo_select_keys(groups.oo_masters_to_config)
  185. | lib_utils_oo_collect('inventory_hostname', {'reconcile_complete': true}) }}"
  186. - set_fact:
  187. reconcile_failed: "{{ groups.oo_masters_to_config | difference(reconcile_completed) | list }}"
  188. - fail:
  189. msg: "Upgrade cannot continue. The following masters did not finish reconciling: {{ reconcile_failed | join(',') }}"
  190. when: reconcile_failed | length > 0
  191. - name: Drain and upgrade master nodes
  192. hosts: oo_masters_to_config:&oo_nodes_to_upgrade
  193. # This var must be set with -e on invocation, as it is not a per-host inventory var
  194. # and is evaluated early. Values such as "20%" can also be used.
  195. serial: "{{ openshift_upgrade_control_plane_nodes_serial | default(1) }}"
  196. max_fail_percentage: "{{ openshift_upgrade_control_plane_nodes_max_fail_percentage | default(0) }}"
  197. pre_tasks:
  198. - name: Load lib_openshift modules
  199. import_role:
  200. name: lib_openshift
  201. roles:
  202. - openshift_facts
  203. post_tasks:
  204. - import_role:
  205. name: openshift_manage_node
  206. tasks_from: config.yml
  207. vars:
  208. openshift_master_host: "{{ groups.oo_first_master.0 }}"
  209. openshift_manage_node_is_master: true