etcd-ca.yml 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. ---
  2. - name: Check cert expirys
  3. hosts: oo_etcd_to_config:oo_masters_to_config
  4. vars:
  5. openshift_certificate_expiry_show_all: yes
  6. roles:
  7. # Sets 'check_results' per host which contains health status for
  8. # etcd, master and node certificates. We will use 'check_results'
  9. # to determine if any certificates were expired prior to running
  10. # this playbook. Service restarts will be skipped if any
  11. # certificates were previously expired.
  12. - role: openshift_certificate_expiry
  13. - name: Backup existing etcd CA certificate directories
  14. hosts: oo_etcd_to_config
  15. roles:
  16. - role: etcd_common
  17. r_etcd_common_etcd_runtime: "{{ openshift.common.etcd_runtime }}"
  18. tasks:
  19. - name: Determine if CA certificate directory exists
  20. stat:
  21. path: "{{ etcd_ca_dir }}"
  22. register: etcd_ca_certs_dir_stat
  23. - name: Backup generated etcd certificates
  24. command: >
  25. tar -czf {{ etcd_conf_dir }}/etcd-ca-certificate-backup-{{ ansible_date_time.epoch }}.tgz
  26. {{ etcd_ca_dir }}
  27. args:
  28. warn: no
  29. when: etcd_ca_certs_dir_stat.stat.exists | bool
  30. - name: Remove CA certificate directory
  31. file:
  32. path: "{{ etcd_ca_dir }}"
  33. state: absent
  34. when: etcd_ca_certs_dir_stat.stat.exists | bool
  35. - name: Generate new etcd CA
  36. hosts: oo_first_etcd
  37. roles:
  38. - role: openshift_etcd_ca
  39. etcd_peers: "{{ groups.oo_etcd_to_config | default([], true) }}"
  40. etcd_ca_host: "{{ groups.oo_etcd_to_config.0 }}"
  41. etcd_certificates_etcd_hosts: "{{ groups.oo_etcd_to_config | default([], true) }}"
  42. - name: Create temp directory for syncing certs
  43. hosts: localhost
  44. connection: local
  45. become: no
  46. gather_facts: no
  47. tasks:
  48. - name: Create local temp directory for syncing certs
  49. local_action: command mktemp -d /tmp/openshift-ansible-XXXXXXX
  50. register: g_etcd_mktemp
  51. changed_when: false
  52. - name: Distribute etcd CA to etcd hosts
  53. hosts: oo_etcd_to_config
  54. vars:
  55. etcd_ca_host: "{{ groups.oo_etcd_to_config.0 }}"
  56. roles:
  57. - role: etcd_common
  58. r_etcd_common_etcd_runtime: "{{ openshift.common.etcd_runtime }}"
  59. tasks:
  60. - name: Create a tarball of the etcd ca certs
  61. command: >
  62. tar -czvf {{ etcd_conf_dir }}/{{ etcd_ca_name }}.tgz
  63. -C {{ etcd_ca_dir }} .
  64. args:
  65. creates: "{{ etcd_conf_dir }}/{{ etcd_ca_name }}.tgz"
  66. warn: no
  67. delegate_to: "{{ etcd_ca_host }}"
  68. run_once: true
  69. - name: Retrieve etcd ca cert tarball
  70. fetch:
  71. src: "{{ etcd_conf_dir }}/{{ etcd_ca_name }}.tgz"
  72. dest: "{{ hostvars['localhost'].g_etcd_mktemp.stdout }}/"
  73. flat: yes
  74. fail_on_missing: yes
  75. validate_checksum: yes
  76. delegate_to: "{{ etcd_ca_host }}"
  77. run_once: true
  78. - name: Ensure ca directory exists
  79. file:
  80. path: "{{ etcd_ca_dir }}"
  81. state: directory
  82. - name: Unarchive etcd ca cert tarballs
  83. unarchive:
  84. src: "{{ hostvars['localhost'].g_etcd_mktemp.stdout }}/{{ etcd_ca_name }}.tgz"
  85. dest: "{{ etcd_ca_dir }}"
  86. - name: Read current etcd CA
  87. slurp:
  88. src: "{{ etcd_conf_dir }}/ca.crt"
  89. register: g_current_etcd_ca_output
  90. - name: Read new etcd CA
  91. slurp:
  92. src: "{{ etcd_ca_dir }}/ca.crt"
  93. register: g_new_etcd_ca_output
  94. - copy:
  95. content: "{{ (g_new_etcd_ca_output.content|b64decode) + (g_current_etcd_ca_output.content|b64decode) }}"
  96. dest: "{{ item }}/ca.crt"
  97. with_items:
  98. - "{{ etcd_conf_dir }}"
  99. - "{{ etcd_ca_dir }}"
  100. - include: ../../openshift-etcd/restart.yml
  101. # Do not restart etcd when etcd certificates were previously expired.
  102. when: ('expired' not in (hostvars
  103. | oo_select_keys(groups['etcd'])
  104. | oo_collect('check_results.check_results.etcd')
  105. | oo_collect('health')))
  106. - name: Retrieve etcd CA certificate
  107. hosts: oo_first_etcd
  108. roles:
  109. - role: etcd_common
  110. r_etcd_common_etcd_runtime: "{{ openshift.common.etcd_runtime }}"
  111. tasks:
  112. - name: Retrieve etcd CA certificate
  113. fetch:
  114. src: "{{ etcd_conf_dir }}/ca.crt"
  115. dest: "{{ hostvars['localhost'].g_etcd_mktemp.stdout }}/"
  116. flat: yes
  117. fail_on_missing: yes
  118. validate_checksum: yes
  119. - name: Distribute etcd CA to masters
  120. hosts: oo_masters_to_config
  121. vars:
  122. openshift_ca_host: "{{ groups.oo_first_master.0 }}"
  123. tasks:
  124. - name: Deploy etcd CA
  125. copy:
  126. src: "{{ hostvars['localhost'].g_etcd_mktemp.stdout }}/ca.crt"
  127. dest: "{{ openshift.common.config_base }}/master/master.etcd-ca.crt"
  128. when: groups.oo_etcd_to_config | default([]) | length > 0
  129. - name: Delete temporary directory on localhost
  130. hosts: localhost
  131. connection: local
  132. become: no
  133. gather_facts: no
  134. tasks:
  135. - file:
  136. name: "{{ g_etcd_mktemp.stdout }}"
  137. state: absent
  138. changed_when: false
  139. - include: ../../openshift-master/restart.yml
  140. # Do not restart masters when master certificates were previously expired.
  141. when: ('expired' not in hostvars
  142. | oo_select_keys(groups['oo_masters_to_config'])
  143. | oo_collect('check_results.check_results.ocp_certs')
  144. | oo_collect('health', {'path':hostvars[groups.oo_first_master.0].openshift.common.config_base ~ "/master/master.server.crt"}))
  145. and
  146. ('expired' not in hostvars
  147. | oo_select_keys(groups['oo_masters_to_config'])
  148. | oo_collect('check_results.check_results.ocp_certs')
  149. | oo_collect('health', {'path':hostvars[groups.oo_first_master.0].openshift.common.config_base ~ "/master/ca-bundle.crt"}))