You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

161 lines
5.0 KiB

  1. ---
  2. - name: Gen_certs | create etcd cert dir
  3. file:
  4. path: "{{ etcd_cert_dir }}"
  5. group: "{{ etcd_cert_group }}"
  6. state: directory
  7. owner: kube
  8. mode: 0700
  9. recurse: yes
  10. - name: "Gen_certs | create etcd script dir (on {{ groups['etcd'][0] }})"
  11. file:
  12. path: "{{ etcd_script_dir }}"
  13. state: directory
  14. owner: root
  15. mode: 0700
  16. run_once: yes
  17. when: inventory_hostname == groups['etcd'][0]
  18. delegate_to: "{{ groups['etcd'][0] }}"
  19. - name: "Gen_certs | create etcd cert dir (on {{ groups['etcd'][0] }})"
  20. file:
  21. path: "{{ etcd_cert_dir }}"
  22. group: "{{ etcd_cert_group }}"
  23. state: directory
  24. owner: kube
  25. recurse: yes
  26. mode: 0700
  27. run_once: yes
  28. when: inventory_hostname == groups['etcd'][0]
  29. delegate_to: "{{ groups['etcd'][0] }}"
  30. - name: Gen_certs | write openssl config
  31. template:
  32. src: "openssl.conf.j2"
  33. dest: "{{ etcd_config_dir }}/openssl.conf"
  34. run_once: yes
  35. delegate_to: "{{ groups['etcd'][0] }}"
  36. when:
  37. - gen_certs|default(false)
  38. - inventory_hostname == groups['etcd'][0]
  39. - name: Gen_certs | copy certs generation script
  40. template:
  41. src: "make-ssl-etcd.sh.j2"
  42. dest: "{{ etcd_script_dir }}/make-ssl-etcd.sh"
  43. mode: 0700
  44. run_once: yes
  45. delegate_to: "{{ groups['etcd'][0] }}"
  46. when:
  47. - gen_certs|default(false)
  48. - inventory_hostname == groups['etcd'][0]
  49. - name: Gen_certs | run cert generation script
  50. command: "bash -x {{ etcd_script_dir }}/make-ssl-etcd.sh -f {{ etcd_config_dir }}/openssl.conf -d {{ etcd_cert_dir }}"
  51. environment:
  52. - MASTERS: "{% for m in groups['etcd'] %}
  53. {% if gen_node_certs[m] %}
  54. {{ m }}
  55. {% endif %}
  56. {% endfor %}"
  57. - HOSTS: "{% for h in (groups['k8s-cluster'] + groups['calico-rr']|default([]))|unique %}
  58. {% if gen_node_certs[h] %}
  59. {{ h }}
  60. {% endif %}
  61. {% endfor %}"
  62. run_once: yes
  63. delegate_to: "{{ groups['etcd'][0] }}"
  64. when:
  65. - gen_certs|default(false)
  66. notify: set etcd_secret_changed
  67. - name: Gen_certs | Gather etcd master certs
  68. slurp:
  69. src: "{{ item }}"
  70. register: etcd_master_certs
  71. with_items:
  72. - "{{ etcd_cert_dir }}/ca.pem"
  73. - "{{ etcd_cert_dir }}/ca-key.pem"
  74. - "[{% for node in groups['etcd'] %}
  75. '{{ etcd_cert_dir }}/admin-{{ node }}.pem',
  76. '{{ etcd_cert_dir }}/admin-{{ node }}-key.pem',
  77. '{{ etcd_cert_dir }}/member-{{ node }}.pem',
  78. '{{ etcd_cert_dir }}/member-{{ node }}-key.pem',
  79. {% endfor %}]"
  80. - "[{% for node in (groups['k8s-cluster'] + groups['calico-rr']|default([]))|unique %}
  81. '{{ etcd_cert_dir }}/node-{{ node }}.pem',
  82. '{{ etcd_cert_dir }}/node-{{ node }}-key.pem',
  83. {% endfor %}]"
  84. delegate_to: "{{ groups['etcd'][0] }}"
  85. when:
  86. - inventory_hostname in groups['etcd']
  87. - sync_certs|default(false)
  88. - inventory_hostname != groups['etcd'][0]
  89. notify: set etcd_secret_changed
  90. - name: Gen_certs | Write etcd master certs
  91. copy:
  92. dest: "{{ item.item }}"
  93. content: "{{ item.content | b64decode }}"
  94. group: "{{ etcd_cert_group }}"
  95. owner: kube
  96. mode: 0640
  97. with_items: "{{ etcd_master_certs.results }}"
  98. when:
  99. - inventory_hostname in groups['etcd']
  100. - sync_certs|default(false)
  101. - inventory_hostname != groups['etcd'][0]
  102. loop_control:
  103. label: "{{ item.item }}"
  104. - name: Gen_certs | Set cert names per node
  105. set_fact:
  106. my_etcd_node_certs: ['ca.pem',
  107. 'node-{{ inventory_hostname }}.pem',
  108. 'node-{{ inventory_hostname }}-key.pem']
  109. tags:
  110. - facts
  111. - name: "Check_certs | Set 'sync_certs' to true on nodes"
  112. set_fact:
  113. sync_certs: true
  114. when: (('calico-rr' in groups and inventory_hostname in groups['calico-rr']) or
  115. inventory_hostname in groups['k8s-cluster']) and
  116. inventory_hostname not in groups['etcd']
  117. with_items:
  118. - "{{ my_etcd_node_certs }}"
  119. - name: Gen_certs | Gather node certs
  120. shell: "tar cfz - -C {{ etcd_cert_dir }} -T /dev/stdin <<< {{ my_etcd_node_certs|join(' ') }} | base64 --wrap=0"
  121. args:
  122. executable: /bin/bash
  123. warn: false
  124. no_log: true
  125. register: etcd_node_certs
  126. check_mode: no
  127. delegate_to: "{{ groups['etcd'][0] }}"
  128. when: (('calico-rr' in groups and inventory_hostname in groups['calico-rr']) or
  129. inventory_hostname in groups['k8s-cluster']) and
  130. sync_certs|default(false) and inventory_hostname not in groups['etcd']
  131. - name: Gen_certs | Copy certs on nodes
  132. shell: "base64 -d <<< '{{ etcd_node_certs.stdout|quote }}' | tar xz -C {{ etcd_cert_dir }}"
  133. args:
  134. executable: /bin/bash
  135. no_log: true
  136. changed_when: false
  137. check_mode: no
  138. when: (('calico-rr' in groups and inventory_hostname in groups['calico-rr']) or
  139. inventory_hostname in groups['k8s-cluster']) and
  140. sync_certs|default(false) and inventory_hostname not in groups['etcd']
  141. notify: set etcd_secret_changed
  142. - name: Gen_certs | check certificate permissions
  143. file:
  144. path: "{{ etcd_cert_dir }}"
  145. group: "{{ etcd_cert_group }}"
  146. state: directory
  147. owner: kube
  148. mode: 0640
  149. recurse: yes