upgrade.yml 8.2 KB

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