redeploy-certificates.yml 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. - stat:
  50. path: "{{ openshift_generated_configs_dir }}"
  51. register: openshift_generated_configs_dir_stat
  52. - name: Backup generated certificate and config directories
  53. command: >
  54. tar -czvf /etc/origin/master-node-cert-config-backup-{{ ansible_date_time.epoch }}.tgz
  55. {{ openshift_generated_configs_dir }}
  56. {{ openshift.common.config_base }}/master
  57. when: openshift_generated_configs_dir_stat.stat.exists
  58. delegate_to: "{{ openshift_ca_host }}"
  59. run_once: true
  60. - name: Remove generated certificate directories
  61. file:
  62. path: "{{ item }}"
  63. state: absent
  64. with_items:
  65. - "{{ openshift_generated_configs_dir }}"
  66. - name: Remove generated certificates
  67. file:
  68. path: "{{ openshift.common.config_base }}/master/{{ item }}"
  69. state: absent
  70. with_items:
  71. - "{{ hostvars[inventory_hostname] | certificates_to_synchronize(include_keys=false) }}"
  72. - "etcd.server.crt"
  73. - "etcd.server.key"
  74. - "master.etcd-client.crt"
  75. - "master.etcd-client.key"
  76. - "master.server.crt"
  77. - "master.server.key"
  78. - "openshift-master.crt"
  79. - "openshift-master.key"
  80. - "openshift-master.kubeconfig"
  81. - name: Remove CA certificate
  82. file:
  83. path: "{{ openshift.common.config_base }}/master/{{ item }}"
  84. state: absent
  85. when: openshift_certificates_redeploy_ca | default(false) | bool
  86. with_items:
  87. - "ca.crt"
  88. - "ca.key"
  89. - "ca.serial.txt"
  90. - "ca-bundle.crt"
  91. roles:
  92. - role: openshift_master_certificates
  93. openshift_master_etcd_hosts: "{{ hostvars
  94. | oo_select_keys(groups['oo_etcd_to_config'] | default([]))
  95. | oo_collect('openshift.common.hostname')
  96. | default(none, true) }}"
  97. openshift_master_hostnames: "{{ hostvars
  98. | oo_select_keys(groups['oo_masters_to_config'] | default([]))
  99. | oo_collect('openshift.common.all_hostnames')
  100. | oo_flatten | unique }}"
  101. openshift_certificates_redeploy: true
  102. - role: openshift_etcd_client_certificates
  103. etcd_certificates_redeploy: true
  104. etcd_ca_host: "{{ groups.oo_etcd_to_config.0 }}"
  105. etcd_cert_subdir: "openshift-master-{{ openshift.common.hostname }}"
  106. etcd_cert_config_dir: "{{ openshift.common.config_base }}/master"
  107. etcd_cert_prefix: "master.etcd-"
  108. when: groups.oo_etcd_to_config is defined and groups.oo_etcd_to_config
  109. - name: Redeploy node certificates
  110. hosts: oo_nodes_to_config
  111. any_errors_fatal: true
  112. pre_tasks:
  113. - name: Remove CA certificate
  114. file:
  115. path: "{{ item }}"
  116. state: absent
  117. with_items:
  118. - "{{ openshift.common.config_base }}/node/ca.crt"
  119. roles:
  120. - role: openshift_node_certificates
  121. openshift_node_master_api_url: "{{ hostvars[groups.oo_first_master.0].openshift.master.api_url }}"
  122. openshift_ca_host: "{{ groups.oo_first_master.0 }}"
  123. openshift_certificates_redeploy: true
  124. - name: Restart etcd
  125. hosts: oo_etcd_to_config
  126. tasks:
  127. - name: restart etcd
  128. service: name=etcd state=restarted
  129. - name: Stop master services
  130. hosts: oo_masters_to_config
  131. vars:
  132. openshift_master_ha: "{{ groups.oo_masters_to_config | length > 1 }}"
  133. tasks:
  134. - name: stop master
  135. service: name={{ openshift.common.service_type }}-master state=stopped
  136. when: not openshift_master_ha | bool
  137. - name: stop master api
  138. service: name={{ openshift.common.service_type }}-master-api state=stopped
  139. when: openshift_master_ha | bool and openshift_master_cluster_method == 'native'
  140. - name: stop master controllers
  141. service: name={{ openshift.common.service_type }}-master-controllers state=stopped
  142. when: openshift_master_ha | bool and openshift_master_cluster_method == 'native'
  143. - name: Start master services
  144. hosts: oo_masters_to_config
  145. serial: 1
  146. vars:
  147. openshift_master_ha: "{{ groups.oo_masters_to_config | length > 1 }}"
  148. tasks:
  149. - name: start master
  150. service: name={{ openshift.common.service_type }}-master state=started
  151. when: not openshift_master_ha | bool
  152. - name: start master api
  153. service: name={{ openshift.common.service_type }}-master-api state=started
  154. when: openshift_master_ha | bool and openshift_master_cluster_method == 'native'
  155. - name: start master controllers
  156. service: name={{ openshift.common.service_type }}-master-controllers state=started
  157. when: openshift_master_ha | bool and openshift_master_cluster_method == 'native'
  158. - name: Restart masters (pacemaker)
  159. hosts: oo_first_master
  160. vars:
  161. openshift_master_ha: "{{ groups.oo_masters_to_config | length > 1 }}"
  162. tasks:
  163. - name: restart master
  164. command: pcs resource restart master
  165. when: openshift_master_ha | bool and openshift_master_cluster_method == 'pacemaker'
  166. - name: Restart nodes
  167. hosts: oo_nodes_to_config
  168. tasks:
  169. - name: restart node
  170. service: name={{ openshift.common.service_type }}-node state=restarted
  171. - name: Copy admin client config(s)
  172. hosts: oo_first_master
  173. tasks:
  174. - name: Create temp directory for kubeconfig
  175. command: mktemp -d /tmp/openshift-ansible-XXXXXX
  176. register: mktemp
  177. changed_when: False
  178. - name: Copy admin client config(s)
  179. command: >
  180. cp {{ openshift.common.config_base }}/master//admin.kubeconfig {{ mktemp.stdout }}/admin.kubeconfig
  181. changed_when: False
  182. - name: Serially evacuate all nodes to trigger redeployments
  183. hosts: oo_nodes_to_config
  184. serial: 1
  185. any_errors_fatal: true
  186. tasks:
  187. - name: Determine if node is currently scheduleable
  188. command: >
  189. {{ openshift.common.client_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig
  190. get node {{ openshift.common.hostname | lower }} -o json
  191. register: node_output
  192. when: openshift_certificates_redeploy_ca | default(false) | bool
  193. delegate_to: "{{ groups.oo_first_master.0 }}"
  194. changed_when: false
  195. - set_fact:
  196. was_schedulable: "{{ 'unschedulable' not in (node_output.stdout | from_json).spec }}"
  197. when: openshift_certificates_redeploy_ca | default(false) | bool
  198. - name: Prepare for node evacuation
  199. command: >
  200. {{ openshift.common.admin_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig
  201. manage-node {{ openshift.common.hostname | lower }}
  202. --schedulable=false
  203. delegate_to: "{{ groups.oo_first_master.0 }}"
  204. when: openshift_certificates_redeploy_ca | default(false) | bool and was_schedulable | bool
  205. - name: Evacuate node
  206. command: >
  207. {{ openshift.common.admin_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig
  208. manage-node {{ openshift.common.hostname | lower }}
  209. --evacuate --force
  210. delegate_to: "{{ groups.oo_first_master.0 }}"
  211. when: openshift_certificates_redeploy_ca | default(false) | bool and was_schedulable | bool
  212. - name: Set node schedulability
  213. command: >
  214. {{ openshift.common.admin_binary }} --config={{ mktemp.stdout }}/admin.kubeconfig
  215. manage-node {{ openshift.common.hostname | lower }} --schedulable=true
  216. delegate_to: "{{ groups.oo_first_master.0 }}"
  217. when: openshift_certificates_redeploy_ca | default(false) | bool and was_schedulable | bool
  218. - name: Delete temporary directory
  219. hosts: oo_first_master
  220. tasks:
  221. - name: Delete temp directory
  222. file:
  223. name: "{{ mktemp.stdout }}"
  224. state: absent
  225. changed_when: False