upgrade_control_plane.yml 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. ---
  2. ###############################################################################
  3. # Upgrade Masters
  4. ###############################################################################
  5. - name: Evaluate additional groups for upgrade
  6. hosts: localhost
  7. connection: local
  8. become: no
  9. tasks:
  10. - name: Evaluate etcd_hosts_to_backup
  11. add_host:
  12. name: "{{ item }}"
  13. groups: etcd_hosts_to_backup
  14. 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 }}"
  15. - name: Backup etcd
  16. hosts: etcd_hosts_to_backup
  17. vars:
  18. embedded_etcd: "{{ hostvars[groups.oo_first_master.0].openshift.master.embedded_etcd }}"
  19. timestamp: "{{ lookup('pipe', 'date +%Y%m%d%H%M%S') }}"
  20. roles:
  21. - openshift_facts
  22. tasks:
  23. # Ensure we persist the etcd role for this host in openshift_facts
  24. - openshift_facts:
  25. role: etcd
  26. local_facts: {}
  27. when: "'etcd' not in openshift"
  28. - stat: path=/var/lib/openshift
  29. register: var_lib_openshift
  30. - stat: path=/var/lib/origin
  31. register: var_lib_origin
  32. - name: Create origin symlink if necessary
  33. file: src=/var/lib/openshift/ dest=/var/lib/origin state=link
  34. when: var_lib_openshift.stat.exists == True and var_lib_origin.stat.exists == False
  35. # TODO: replace shell module with command and update later checks
  36. # We assume to be using the data dir for all backups.
  37. - name: Check available disk space for etcd backup
  38. shell: df --output=avail -k {{ openshift.common.data_dir }} | tail -n 1
  39. register: avail_disk
  40. # TODO: replace shell module with command and update later checks
  41. - name: Check current embedded etcd disk usage
  42. shell: du -k {{ openshift.etcd.etcd_data_dir }} | tail -n 1 | cut -f1
  43. register: etcd_disk_usage
  44. when: embedded_etcd | bool
  45. - name: Abort if insufficient disk space for etcd backup
  46. fail:
  47. msg: >
  48. {{ etcd_disk_usage.stdout }} Kb disk space required for etcd backup,
  49. {{ avail_disk.stdout }} Kb available.
  50. when: (embedded_etcd | bool) and (etcd_disk_usage.stdout|int > avail_disk.stdout|int)
  51. - name: Install etcd (for etcdctl)
  52. action: "{{ ansible_pkg_mgr }} name=etcd state=latest"
  53. when: not openshift.common.is_atomic | bool
  54. - name: Generate etcd backup
  55. command: >
  56. etcdctl backup --data-dir={{ openshift.etcd.etcd_data_dir }}
  57. --backup-dir={{ openshift.common.data_dir }}/etcd-backup-{{ timestamp }}
  58. - set_fact:
  59. etcd_backup_complete: True
  60. - name: Display location of etcd backup
  61. debug:
  62. msg: "Etcd backup created in {{ openshift.common.data_dir }}/etcd-backup-{{ timestamp }}"
  63. - name: Gate on etcd backup
  64. hosts: localhost
  65. connection: local
  66. become: no
  67. tasks:
  68. - set_fact:
  69. etcd_backup_completed: "{{ hostvars
  70. | oo_select_keys(groups.etcd_hosts_to_backup)
  71. | oo_collect('inventory_hostname', {'etcd_backup_complete': true}) }}"
  72. - set_fact:
  73. etcd_backup_failed: "{{ groups.etcd_hosts_to_backup | difference(etcd_backup_completed) }}"
  74. - fail:
  75. msg: "Upgrade cannot continue. The following hosts did not complete etcd backup: {{ etcd_backup_failed | join(',') }}"
  76. when: etcd_backup_failed | length > 0
  77. - name: Upgrade master packages
  78. hosts: oo_masters_to_config
  79. handlers:
  80. - include: ../../../../roles/openshift_master/handlers/main.yml
  81. static: yes
  82. roles:
  83. - openshift_facts
  84. tasks:
  85. - include: rpm_upgrade.yml component=master
  86. when: not openshift.common.is_containerized | bool
  87. # Create service signer cert when missing. Service signer certificate
  88. # is added to master config in the master config hook for v3_3.
  89. - name: Determine if service signer cert must be created
  90. hosts: oo_first_master
  91. tasks:
  92. - name: Determine if service signer certificate must be created
  93. stat:
  94. path: "{{ openshift.common.config_base }}/master/service-signer.crt"
  95. register: service_signer_cert_stat
  96. changed_when: false
  97. - include: create_service_signer_cert.yml
  98. - name: Upgrade master config and systemd units
  99. hosts: oo_masters_to_config
  100. handlers:
  101. - include: ../../../../roles/openshift_master/handlers/main.yml
  102. static: yes
  103. roles:
  104. - openshift_facts
  105. tasks:
  106. - include: "{{ master_config_hook }}"
  107. when: master_config_hook is defined
  108. - include_vars: ../../../../roles/openshift_master/vars/main.yml
  109. - name: Update systemd units
  110. include: ../../../../roles/openshift_master/tasks/systemd_units.yml
  111. - name: Check for ca-bundle.crt
  112. stat:
  113. path: "{{ openshift.common.config_base }}/master/ca-bundle.crt"
  114. register: ca_bundle_stat
  115. failed_when: false
  116. - name: Check for ca.crt
  117. stat:
  118. path: "{{ openshift.common.config_base }}/master/ca.crt"
  119. register: ca_crt_stat
  120. failed_when: false
  121. - name: Migrate ca.crt to ca-bundle.crt
  122. command: mv ca.crt ca-bundle.crt
  123. args:
  124. chdir: "{{ openshift.common.config_base }}/master"
  125. when: ca_crt_stat.stat.isreg and not ca_bundle_stat.stat.exists
  126. - name: Link ca.crt to ca-bundle.crt
  127. file:
  128. src: "{{ openshift.common.config_base }}/master/ca-bundle.crt"
  129. path: "{{ openshift.common.config_base }}/master/ca.crt"
  130. state: link
  131. when: ca_crt_stat.stat.isreg and not ca_bundle_stat.stat.exists
  132. - name: Set master update status to complete
  133. hosts: oo_masters_to_config
  134. tasks:
  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. become: no
  144. tasks:
  145. - set_fact:
  146. master_update_completed: "{{ hostvars
  147. | oo_select_keys(groups.oo_masters_to_config)
  148. | oo_collect('inventory_hostname', {'master_update_complete': true}) }}"
  149. - set_fact:
  150. master_update_failed: "{{ groups.oo_masters_to_config | difference(master_update_completed) }}"
  151. - fail:
  152. msg: "Upgrade cannot continue. The following masters did not finish updating: {{ master_update_failed | join(',') }}"
  153. when: master_update_failed | length > 0
  154. # We are now ready to restart master services (or entire system
  155. # depending on openshift_rolling_restart_mode):
  156. - include: ../../openshift-master/restart.yml
  157. ###############################################################################
  158. # Reconcile Cluster Roles, Cluster Role Bindings and Security Context Constraints
  159. ###############################################################################
  160. - name: Reconcile Cluster Roles and Cluster Role Bindings and Security Context Constraints
  161. hosts: oo_masters_to_config
  162. roles:
  163. - { role: openshift_cli }
  164. vars:
  165. origin_reconcile_bindings: "{{ deployment_type == 'origin' and openshift_version | version_compare('1.0.6', '>') }}"
  166. ent_reconcile_bindings: true
  167. openshift_docker_hosted_registry_network: "{{ hostvars[groups.oo_first_master.0].openshift.common.portal_net }}"
  168. # Another spot where we assume docker is running and do not want to accidentally trigger an unsafe
  169. # restart.
  170. skip_docker_role: True
  171. tasks:
  172. - name: Reconcile Cluster Roles
  173. command: >
  174. {{ openshift.common.client_binary }} adm --config={{ openshift.common.config_base }}/master/admin.kubeconfig
  175. policy reconcile-cluster-roles --additive-only=true --confirm
  176. run_once: true
  177. - name: Reconcile Cluster Role Bindings
  178. command: >
  179. {{ openshift.common.client_binary }} adm --config={{ openshift.common.config_base }}/master/admin.kubeconfig
  180. policy reconcile-cluster-role-bindings
  181. --exclude-groups=system:authenticated
  182. --exclude-groups=system:authenticated:oauth
  183. --exclude-groups=system:unauthenticated
  184. --exclude-users=system:anonymous
  185. --additive-only=true --confirm
  186. when: origin_reconcile_bindings | bool or ent_reconcile_bindings | bool
  187. run_once: true
  188. - name: Reconcile Security Context Constraints
  189. command: >
  190. {{ openshift.common.client_binary }} adm policy reconcile-sccs --confirm --additive-only=true
  191. run_once: true
  192. - set_fact:
  193. reconcile_complete: True
  194. ##############################################################################
  195. # Gate on reconcile
  196. ##############################################################################
  197. - name: Gate on reconcile
  198. hosts: localhost
  199. connection: local
  200. become: no
  201. tasks:
  202. - set_fact:
  203. reconcile_completed: "{{ hostvars
  204. | oo_select_keys(groups.oo_masters_to_config)
  205. | oo_collect('inventory_hostname', {'reconcile_complete': true}) }}"
  206. - set_fact:
  207. reconcile_failed: "{{ groups.oo_masters_to_config | difference(reconcile_completed) }}"
  208. - fail:
  209. msg: "Upgrade cannot continue. The following masters did not finish reconciling: {{ reconcile_failed | join(',') }}"
  210. when: reconcile_failed | length > 0
  211. - name: Upgrade Docker on dedicated containerized etcd hosts
  212. hosts: oo_etcd_to_config:!oo_nodes_to_upgrade
  213. serial: 1
  214. any_errors_fatal: true
  215. roles:
  216. - openshift_facts
  217. tasks:
  218. - include: docker/upgrade.yml
  219. when: l_docker_upgrade is defined and l_docker_upgrade | bool and not openshift.common.is_atomic | bool