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.

162 lines
5.6 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=root
  8. recurse=yes
  9. - name: "Gen_certs | create etcd script dir (on {{groups['etcd'][0]}})"
  10. file:
  11. path: "{{ etcd_script_dir }}"
  12. state: directory
  13. owner: root
  14. run_once: yes
  15. delegate_to: "{{groups['etcd'][0]}}"
  16. - name: "Gen_certs | create etcd cert dir (on {{groups['etcd'][0]}})"
  17. file:
  18. path={{ etcd_cert_dir }}
  19. group={{ etcd_cert_group }}
  20. state=directory
  21. owner=root
  22. recurse=yes
  23. run_once: yes
  24. delegate_to: "{{groups['etcd'][0]}}"
  25. - name: Gen_certs | write openssl config
  26. template:
  27. src: "openssl.conf.j2"
  28. dest: "{{ etcd_config_dir }}/openssl.conf"
  29. run_once: yes
  30. delegate_to: "{{groups['etcd'][0]}}"
  31. when: gen_certs|default(false)
  32. - name: Gen_certs | copy certs generation script
  33. copy:
  34. src: "make-ssl-etcd.sh"
  35. dest: "{{ etcd_script_dir }}/make-ssl-etcd.sh"
  36. mode: 0700
  37. run_once: yes
  38. delegate_to: "{{groups['etcd'][0]}}"
  39. when: gen_certs|default(false)
  40. - name: Gen_certs | run cert generation script
  41. command: "{{ etcd_script_dir }}/make-ssl-etcd.sh -f {{ etcd_config_dir }}/openssl.conf -d {{ etcd_cert_dir }}"
  42. environment:
  43. - MASTERS: "{% for m in groups['etcd'] %}
  44. {% if hostvars[m].sync_certs|default(false) %}
  45. {{ m }}
  46. {% endif %}
  47. {% endfor %}"
  48. - HOSTS: "{% for h in (groups['k8s-cluster'] + groups['calico-rr']|default([]))|unique %}
  49. {% if hostvars[h].sync_certs|default(false) %}
  50. {{ h }}
  51. {% endif %}
  52. {% endfor %}"
  53. run_once: yes
  54. delegate_to: "{{groups['etcd'][0]}}"
  55. when: gen_certs|default(false)
  56. notify: set etcd_secret_changed
  57. - set_fact:
  58. all_master_certs: "['ca-key.pem',
  59. {% for node in groups['etcd'] %}
  60. 'admin-{{ node }}.pem',
  61. 'admin-{{ node }}-key.pem',
  62. 'member-{{ node }}.pem',
  63. 'member-{{ node }}-key.pem',
  64. {% endfor %}]"
  65. my_master_certs: ['ca-key.pem',
  66. 'admin-{{ inventory_hostname }}.pem',
  67. 'admin-{{ inventory_hostname }}-key.pem',
  68. 'member-{{ inventory_hostname }}.pem',
  69. 'member-{{ inventory_hostname }}-key.pem'
  70. ]
  71. all_node_certs: "['ca.pem',
  72. {% for node in (groups['k8s-cluster'] + groups['calico-rr']|default([]))|unique %}
  73. 'node-{{ node }}.pem',
  74. 'node-{{ node }}-key.pem',
  75. {% endfor %}]"
  76. my_node_certs: ['ca.pem', 'node-{{ inventory_hostname }}.pem', 'node-{{ inventory_hostname }}-key.pem']
  77. tags: facts
  78. - name: Gen_certs | Gather etcd master certs
  79. shell: "tar cfz - -C {{ etcd_cert_dir }} -T /dev/stdin <<< {{ my_master_certs|join(' ') }} {{ all_node_certs|join(' ') }} | base64 --wrap=0"
  80. args:
  81. executable: /bin/bash
  82. register: etcd_master_cert_data
  83. delegate_to: "{{groups['etcd'][0]}}"
  84. when: inventory_hostname in groups['etcd'] and sync_certs|default(false) and
  85. inventory_hostname != groups['etcd'][0]
  86. notify: set etcd_secret_changed
  87. - name: Gen_certs | Gather etcd node certs
  88. shell: "tar cfz - -C {{ etcd_cert_dir }} -T /dev/stdin <<< {{ my_node_certs|join(' ') }} | base64 --wrap=0"
  89. args:
  90. executable: /bin/bash
  91. register: etcd_node_cert_data
  92. delegate_to: "{{groups['etcd'][0]}}"
  93. when: (('calico-rr' in groups and inventory_hostname in groups['calico-rr']) or
  94. inventory_hostname in groups['k8s-cluster']) and
  95. sync_certs|default(false) and inventory_hostname not in groups['etcd']
  96. notify: set etcd_secret_changed
  97. - name: Gen_certs | Copy certs on masters
  98. shell: "base64 -d <<< '{{etcd_master_cert_data.stdout|quote}}' | tar xz -C {{ etcd_cert_dir }}"
  99. args:
  100. executable: /bin/bash
  101. changed_when: false
  102. when: inventory_hostname in groups['etcd'] and sync_certs|default(false) and
  103. inventory_hostname != groups['etcd'][0]
  104. - name: Gen_certs | Copy certs on nodes
  105. shell: "base64 -d <<< '{{etcd_node_cert_data.stdout|quote}}' | tar xz -C {{ etcd_cert_dir }}"
  106. args:
  107. executable: /bin/bash
  108. changed_when: false
  109. when: sync_certs|default(false) and
  110. inventory_hostname not in groups['etcd']
  111. - name: Gen_certs | check certificate permissions
  112. file:
  113. path={{ etcd_cert_dir }}
  114. group={{ etcd_cert_group }}
  115. state=directory
  116. owner=kube
  117. recurse=yes
  118. tags: facts
  119. - name: Gen_certs | set permissions on keys
  120. shell: chmod 0600 {{ etcd_cert_dir}}/*key.pem
  121. when: inventory_hostname in groups['etcd']
  122. changed_when: false
  123. - name: Gen_certs | target ca-certificate store file
  124. set_fact:
  125. ca_cert_path: |-
  126. {% if ansible_os_family == "Debian" -%}
  127. /usr/local/share/ca-certificates/etcd-ca.crt
  128. {%- elif ansible_os_family == "RedHat" -%}
  129. /etc/pki/ca-trust/source/anchors/etcd-ca.crt
  130. {%- elif ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] -%}
  131. /etc/ssl/certs/etcd-ca.pem
  132. {%- endif %}
  133. tags: facts
  134. - name: Gen_certs | add CA to trusted CA dir
  135. copy:
  136. src: "{{ etcd_cert_dir }}/ca.pem"
  137. dest: "{{ ca_cert_path }}"
  138. remote_src: true
  139. register: etcd_ca_cert
  140. - name: Gen_certs | update ca-certificates (Debian/Ubuntu/Container Linux by CoreOS)
  141. command: update-ca-certificates
  142. when: etcd_ca_cert.changed and ansible_os_family in ["Debian", "Container Linux by CoreOS"]
  143. - name: Gen_certs | update ca-certificates (RedHat)
  144. command: update-ca-trust extract
  145. when: etcd_ca_cert.changed and ansible_os_family == "RedHat"