redeploy-certificates.yml 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. ---
  2. - include: evaluate_groups.yml
  3. - include: initialize_facts.yml
  4. - include: initialize_openshift_version.yml
  5. - name: Load openshift_facts
  6. hosts: oo_etcd_to_config:oo_masters_to_config:oo_nodes_to_config
  7. roles:
  8. - openshift_facts
  9. - name: Redeploy etcd certificates
  10. hosts: oo_etcd_to_config
  11. any_errors_fatal: true
  12. vars:
  13. etcd_ca_host: "{{ groups.oo_etcd_to_config.0 }}"
  14. etcd_conf_dir: /etc/etcd
  15. etcd_generated_certs_dir: "{{ etcd_conf_dir }}/generated_certs"
  16. pre_tasks:
  17. - stat:
  18. path: "{{ etcd_generated_certs_dir }}"
  19. register: etcd_generated_certs_dir_stat
  20. - name: Backup etcd certificates
  21. command: >
  22. tar -czvf /etc/etcd/etcd-certificate-backup-{{ ansible_date_time.epoch }}.tgz
  23. {{ etcd_conf_dir }}/ca.crt
  24. {{ etcd_conf_dir }}/ca
  25. {{ etcd_generated_certs_dir }}
  26. when: etcd_generated_certs_dir_stat.stat.exists
  27. delegate_to: "{{ etcd_ca_host }}"
  28. run_once: true
  29. - name: Remove existing etcd certificates
  30. file:
  31. path: "{{ item }}"
  32. state: absent
  33. with_items:
  34. - "{{ etcd_conf_dir }}/ca.crt"
  35. - "{{ etcd_conf_dir }}/ca"
  36. - "{{ etcd_generated_certs_dir }}"
  37. roles:
  38. - role: openshift_etcd_server_certificates
  39. etcd_peers: "{{ groups.oo_etcd_to_config | default([], true) }}"
  40. etcd_certificates_etcd_hosts: "{{ groups.oo_etcd_to_config | default([], true) }}"
  41. etcd_certificates_redeploy: true
  42. - name: Redeploy master certificates
  43. hosts: oo_masters_to_config
  44. any_errors_fatal: true
  45. vars:
  46. openshift_ca_host: "{{ groups.oo_first_master.0 }}"
  47. openshift_master_count: "{{ openshift.master.master_count | default(groups.oo_masters | length) }}"
  48. pre_tasks:
  49. # set_fact task copied from playbooks/common/openshift-master/config.yml
  50. # so that openshift_master_default_subdomain has a default value of ""
  51. # (emptry string). openshift_master_default_subdomain must have a default
  52. # value for openshift_master_facts to set metrics_public_url.
  53. # TODO: clean this up.
  54. - set_fact:
  55. openshift_master_default_subdomain: "{{ lookup('oo_option', 'openshift_master_default_subdomain') | default(None, true) }}"
  56. when: openshift_master_default_subdomain is not defined
  57. - stat:
  58. path: "{{ openshift_generated_configs_dir }}"
  59. register: openshift_generated_configs_dir_stat
  60. - name: Backup generated certificate and config directories
  61. command: >
  62. tar -czvf /etc/origin/master-node-cert-config-backup-{{ ansible_date_time.epoch }}.tgz
  63. {{ openshift_generated_configs_dir }}
  64. {{ openshift.common.config_base }}/master
  65. when: openshift_generated_configs_dir_stat.stat.exists
  66. delegate_to: "{{ openshift_ca_host }}"
  67. run_once: true
  68. - name: Remove generated certificate directories
  69. file:
  70. path: "{{ item }}"
  71. state: absent
  72. with_items:
  73. - "{{ openshift_generated_configs_dir }}"
  74. - name: Remove generated certificates
  75. file:
  76. path: "{{ openshift.common.config_base }}/master/{{ item }}"
  77. state: absent
  78. with_items:
  79. - "{{ hostvars[inventory_hostname] | certificates_to_synchronize(include_keys=false) }}"
  80. - "etcd.server.crt"
  81. - "etcd.server.key"
  82. - "master.etcd-client.crt"
  83. - "master.etcd-client.key"
  84. - "master.server.crt"
  85. - "master.server.key"
  86. - "openshift-master.crt"
  87. - "openshift-master.key"
  88. - "openshift-master.kubeconfig"
  89. - name: Remove CA certificate
  90. file:
  91. path: "{{ openshift.common.config_base }}/master/{{ item }}"
  92. state: absent
  93. when: openshift_certificates_redeploy_ca | default(false) | bool
  94. with_items:
  95. - "ca.crt"
  96. - "ca.key"
  97. - "ca.serial.txt"
  98. - "ca-bundle.crt"
  99. roles:
  100. - role: openshift_master_certificates
  101. openshift_master_etcd_hosts: "{{ hostvars
  102. | oo_select_keys(groups['oo_etcd_to_config'] | default([]))
  103. | oo_collect('openshift.common.hostname')
  104. | default(none, true) }}"
  105. openshift_master_hostnames: "{{ hostvars
  106. | oo_select_keys(groups['oo_masters_to_config'] | default([]))
  107. | oo_collect('openshift.common.all_hostnames')
  108. | oo_flatten | unique }}"
  109. openshift_certificates_redeploy: true
  110. - role: openshift_etcd_client_certificates
  111. etcd_certificates_redeploy: true
  112. etcd_ca_host: "{{ groups.oo_etcd_to_config.0 }}"
  113. etcd_cert_subdir: "openshift-master-{{ openshift.common.hostname }}"
  114. etcd_cert_config_dir: "{{ openshift.common.config_base }}/master"
  115. etcd_cert_prefix: "master.etcd-"
  116. when: groups.oo_etcd_to_config is defined and groups.oo_etcd_to_config
  117. - name: Redeploy node certificates
  118. hosts: oo_nodes_to_config
  119. any_errors_fatal: true
  120. pre_tasks:
  121. - name: Remove CA certificate
  122. file:
  123. path: "{{ item }}"
  124. state: absent
  125. with_items:
  126. - "{{ openshift.common.config_base }}/node/ca.crt"
  127. roles:
  128. - role: openshift_node_certificates
  129. openshift_node_master_api_url: "{{ hostvars[groups.oo_first_master.0].openshift.master.api_url }}"
  130. openshift_ca_host: "{{ groups.oo_first_master.0 }}"
  131. openshift_certificates_redeploy: true
  132. - name: Restart etcd
  133. hosts: oo_etcd_to_config
  134. tasks:
  135. - name: restart etcd
  136. service:
  137. name: "{{ 'etcd' if not openshift.common.is_containerized | bool else 'etcd_container' }}"
  138. state: restarted
  139. - name: Stop master services
  140. hosts: oo_masters_to_config
  141. vars:
  142. openshift_master_ha: "{{ groups.oo_masters_to_config | length > 1 }}"
  143. tasks:
  144. - name: stop master
  145. service: name={{ openshift.common.service_type }}-master state=stopped
  146. when: not openshift_master_ha | bool
  147. - name: stop master api
  148. service: name={{ openshift.common.service_type }}-master-api state=stopped
  149. when: openshift_master_ha | bool and openshift_master_cluster_method == 'native'
  150. - name: stop master controllers
  151. service: name={{ openshift.common.service_type }}-master-controllers state=stopped
  152. when: openshift_master_ha | bool and openshift_master_cluster_method == 'native'
  153. - name: Start master services
  154. hosts: oo_masters_to_config
  155. serial: 1
  156. vars:
  157. openshift_master_ha: "{{ groups.oo_masters_to_config | length > 1 }}"
  158. tasks:
  159. - name: start master
  160. service: name={{ openshift.common.service_type }}-master state=started
  161. when: not openshift_master_ha | bool
  162. - name: start master api
  163. service: name={{ openshift.common.service_type }}-master-api state=started
  164. when: openshift_master_ha | bool and openshift_master_cluster_method == 'native'
  165. - name: start master controllers
  166. service: name={{ openshift.common.service_type }}-master-controllers state=started
  167. when: openshift_master_ha | bool and openshift_master_cluster_method == 'native'
  168. - name: Restart masters (pacemaker)
  169. hosts: oo_first_master
  170. vars:
  171. openshift_master_ha: "{{ groups.oo_masters_to_config | length > 1 }}"
  172. tasks:
  173. - name: restart master
  174. command: pcs resource restart master
  175. when: openshift_master_ha | bool and openshift_master_cluster_method == 'pacemaker'
  176. - name: Restart nodes
  177. hosts: oo_nodes_to_config
  178. tasks:
  179. - name: restart node
  180. service: name={{ openshift.common.service_type }}-node state=restarted
  181. - name: Copy admin client config(s)
  182. hosts: oo_first_master
  183. tasks:
  184. - name: Create temp directory for kubeconfig
  185. command: mktemp -d /tmp/openshift-ansible-XXXXXX
  186. register: mktemp
  187. changed_when: False
  188. - name: Copy admin client config(s)
  189. command: >
  190. cp {{ openshift.common.config_base }}/master//admin.kubeconfig {{ mktemp.stdout }}/admin.kubeconfig
  191. changed_when: False
  192. - name: Serially evacuate all nodes to trigger redeployments
  193. hosts: oo_nodes_to_config
  194. serial: 1
  195. any_errors_fatal: true
  196. tasks:
  197. - name: Determine if node is currently scheduleable
  198. command: >
  199. {{ openshift.common.client_binary }} --config={{ hostvars[groups.oo_first_master.0].mktemp.stdout }}/admin.kubeconfig
  200. get node {{ openshift.node.nodename }} -o json
  201. register: node_output
  202. when: openshift_certificates_redeploy_ca | default(false) | bool
  203. delegate_to: "{{ groups.oo_first_master.0 }}"
  204. changed_when: false
  205. - set_fact:
  206. was_schedulable: "{{ 'unschedulable' not in (node_output.stdout | from_json).spec }}"
  207. when: openshift_certificates_redeploy_ca | default(false) | bool
  208. - name: Prepare for node evacuation
  209. command: >
  210. {{ openshift.common.admin_binary }} --config={{ hostvars[groups.oo_first_master.0].mktemp.stdout }}/admin.kubeconfig
  211. manage-node {{ openshift.node.nodename }}
  212. --schedulable=false
  213. delegate_to: "{{ groups.oo_first_master.0 }}"
  214. when: openshift_certificates_redeploy_ca | default(false) | bool and was_schedulable | bool
  215. - name: Evacuate node
  216. command: >
  217. {{ openshift.common.admin_binary }} --config={{ hostvars[groups.oo_first_master.0].mktemp.stdout }}/admin.kubeconfig
  218. manage-node {{ openshift.node.nodename }}
  219. --evacuate --force
  220. delegate_to: "{{ groups.oo_first_master.0 }}"
  221. when: openshift_certificates_redeploy_ca | default(false) | bool and was_schedulable | bool
  222. - name: Set node schedulability
  223. command: >
  224. {{ openshift.common.admin_binary }} --config={{ hostvars[groups.oo_first_master.0].mktemp.stdout }}/admin.kubeconfig
  225. manage-node {{ openshift.node.nodename }} --schedulable=true
  226. delegate_to: "{{ groups.oo_first_master.0 }}"
  227. when: openshift_certificates_redeploy_ca | default(false) | bool and was_schedulable | bool
  228. - name: Delete temporary directory
  229. hosts: oo_first_master
  230. tasks:
  231. - name: Delete temp directory
  232. file:
  233. name: "{{ mktemp.stdout }}"
  234. state: absent
  235. changed_when: False