2016-11-09 10:44:41 +00:00
|
|
|
---
|
2017-01-15 05:24:34 +00:00
|
|
|
- name: Gen_certs | create etcd cert dir
|
|
|
|
file:
|
2017-02-17 21:22:34 +00:00
|
|
|
path: "{{ etcd_cert_dir }}"
|
|
|
|
group: "{{ etcd_cert_group }}"
|
|
|
|
state: directory
|
2022-06-17 08:34:32 +00:00
|
|
|
owner: "{{ etcd_owner }}"
|
2020-12-09 08:48:49 +00:00
|
|
|
mode: "{{ etcd_cert_dir_mode }}"
|
2017-02-17 21:22:34 +00:00
|
|
|
recurse: yes
|
2016-11-09 10:44:41 +00:00
|
|
|
|
2019-05-02 21:24:21 +00:00
|
|
|
- name: "Gen_certs | create etcd script dir (on {{ groups['etcd'][0] }})"
|
2016-11-09 10:44:41 +00:00
|
|
|
file:
|
|
|
|
path: "{{ etcd_script_dir }}"
|
|
|
|
state: directory
|
2017-02-06 12:58:54 +00:00
|
|
|
owner: root
|
2017-03-14 14:23:29 +00:00
|
|
|
mode: 0700
|
2017-01-15 05:24:34 +00:00
|
|
|
run_once: yes
|
2018-04-01 16:58:08 +00:00
|
|
|
when: inventory_hostname == groups['etcd'][0]
|
2016-11-09 10:44:41 +00:00
|
|
|
|
|
|
|
- name: Gen_certs | write openssl config
|
|
|
|
template:
|
|
|
|
src: "openssl.conf.j2"
|
|
|
|
dest: "{{ etcd_config_dir }}/openssl.conf"
|
2021-07-12 07:00:47 +00:00
|
|
|
mode: 0640
|
2016-11-09 10:44:41 +00:00
|
|
|
run_once: yes
|
2019-05-02 21:24:21 +00:00
|
|
|
delegate_to: "{{ groups['etcd'][0] }}"
|
2018-04-01 16:58:08 +00:00
|
|
|
when:
|
|
|
|
- gen_certs|default(false)
|
|
|
|
- inventory_hostname == groups['etcd'][0]
|
2016-11-09 10:44:41 +00:00
|
|
|
|
|
|
|
- name: Gen_certs | copy certs generation script
|
2018-10-09 11:43:30 +00:00
|
|
|
template:
|
|
|
|
src: "make-ssl-etcd.sh.j2"
|
2016-11-09 10:44:41 +00:00
|
|
|
dest: "{{ etcd_script_dir }}/make-ssl-etcd.sh"
|
|
|
|
mode: 0700
|
|
|
|
run_once: yes
|
2018-04-01 16:58:08 +00:00
|
|
|
when:
|
|
|
|
- gen_certs|default(false)
|
|
|
|
- inventory_hostname == groups['etcd'][0]
|
2017-03-14 14:23:29 +00:00
|
|
|
|
2022-09-09 08:29:22 +00:00
|
|
|
- name: Gen_certs | run cert generation script for etcd and kube control plane nodes
|
2017-03-03 13:21:01 +00:00
|
|
|
command: "bash -x {{ etcd_script_dir }}/make-ssl-etcd.sh -f {{ etcd_config_dir }}/openssl.conf -d {{ etcd_cert_dir }}"
|
2016-12-13 09:03:35 +00:00
|
|
|
environment:
|
|
|
|
- MASTERS: "{% for m in groups['etcd'] %}
|
2020-03-25 19:46:25 +00:00
|
|
|
{% if gen_master_certs[m] %}
|
2016-12-13 09:03:35 +00:00
|
|
|
{{ m }}
|
|
|
|
{% endif %}
|
|
|
|
{% endfor %}"
|
2022-09-09 08:29:22 +00:00
|
|
|
- HOSTS: "{% for h in groups['kube_control_plane'] %}
|
2017-03-03 13:21:01 +00:00
|
|
|
{% if gen_node_certs[h] %}
|
2016-12-13 09:03:35 +00:00
|
|
|
{{ h }}
|
|
|
|
{% endif %}
|
|
|
|
{% endfor %}"
|
2016-11-09 10:44:41 +00:00
|
|
|
run_once: yes
|
2019-05-02 21:24:21 +00:00
|
|
|
delegate_to: "{{ groups['etcd'][0] }}"
|
2021-02-09 09:53:22 +00:00
|
|
|
when: gen_certs|default(false)
|
2016-11-09 10:44:41 +00:00
|
|
|
notify: set etcd_secret_changed
|
|
|
|
|
2022-09-09 08:29:22 +00:00
|
|
|
- name: Gen_certs | run cert generation script for all clients
|
|
|
|
command: "bash -x {{ etcd_script_dir }}/make-ssl-etcd.sh -f {{ etcd_config_dir }}/openssl.conf -d {{ etcd_cert_dir }}"
|
|
|
|
environment:
|
|
|
|
- HOSTS: "{% for h in groups['k8s_cluster'] %}
|
|
|
|
{% if gen_node_certs[h] %}
|
|
|
|
{{ h }}
|
|
|
|
{% endif %}
|
|
|
|
{% endfor %}"
|
|
|
|
run_once: yes
|
|
|
|
delegate_to: "{{ groups['etcd'][0] }}"
|
|
|
|
when:
|
|
|
|
- kube_network_plugin in ["calico", "flannel", "canal", "cilium"] or cilium_deploy_additionally | default(false) | bool
|
|
|
|
- kube_network_plugin != "calico" or calico_datastore == "etcd"
|
|
|
|
- gen_certs|default(false)
|
|
|
|
notify: set etcd_secret_changed
|
|
|
|
|
|
|
|
- name: Gen_certs | Gather etcd member/admin and kube_control_plane clinet certs from first etcd node
|
2018-09-27 09:12:02 +00:00
|
|
|
slurp:
|
|
|
|
src: "{{ item }}"
|
|
|
|
register: etcd_master_certs
|
|
|
|
with_items:
|
|
|
|
- "{{ etcd_cert_dir }}/ca.pem"
|
|
|
|
- "{{ etcd_cert_dir }}/ca-key.pem"
|
|
|
|
- "[{% for node in groups['etcd'] %}
|
|
|
|
'{{ etcd_cert_dir }}/admin-{{ node }}.pem',
|
|
|
|
'{{ etcd_cert_dir }}/admin-{{ node }}-key.pem',
|
|
|
|
'{{ etcd_cert_dir }}/member-{{ node }}.pem',
|
|
|
|
'{{ etcd_cert_dir }}/member-{{ node }}-key.pem',
|
|
|
|
{% endfor %}]"
|
2022-09-09 08:29:22 +00:00
|
|
|
- "[{% for node in (groups['kube_control_plane']) %}
|
|
|
|
'{{ etcd_cert_dir }}/node-{{ node }}.pem',
|
|
|
|
'{{ etcd_cert_dir }}/node-{{ node }}-key.pem',
|
|
|
|
{% endfor %}]"
|
2021-02-09 09:53:22 +00:00
|
|
|
delegate_to: "{{ groups['etcd'][0] }}"
|
|
|
|
when:
|
|
|
|
- inventory_hostname in groups['etcd']
|
|
|
|
- sync_certs|default(false)
|
|
|
|
- inventory_hostname != groups['etcd'][0]
|
|
|
|
notify: set etcd_secret_changed
|
|
|
|
|
2022-09-09 08:29:22 +00:00
|
|
|
- name: Gen_certs | Write etcd member/admin and kube_control_plane clinet certs to other etcd nodes
|
2021-02-09 09:53:22 +00:00
|
|
|
copy:
|
|
|
|
dest: "{{ item.item }}"
|
|
|
|
content: "{{ item.content | b64decode }}"
|
|
|
|
group: "{{ etcd_cert_group }}"
|
2022-06-17 08:34:32 +00:00
|
|
|
owner: "{{ etcd_owner }}"
|
2021-02-09 09:53:22 +00:00
|
|
|
mode: 0640
|
|
|
|
with_items: "{{ etcd_master_certs.results }}"
|
|
|
|
when:
|
|
|
|
- inventory_hostname in groups['etcd']
|
|
|
|
- sync_certs|default(false)
|
|
|
|
- inventory_hostname != groups['etcd'][0]
|
|
|
|
loop_control:
|
|
|
|
label: "{{ item.item }}"
|
|
|
|
|
|
|
|
- name: Gen_certs | Gather node certs from first etcd node
|
|
|
|
slurp:
|
|
|
|
src: "{{ item }}"
|
|
|
|
register: etcd_master_node_certs
|
|
|
|
with_items:
|
2022-09-09 08:29:22 +00:00
|
|
|
- "[{% for node in groups['k8s_cluster'] %}
|
2018-09-27 09:12:02 +00:00
|
|
|
'{{ etcd_cert_dir }}/node-{{ node }}.pem',
|
|
|
|
'{{ etcd_cert_dir }}/node-{{ node }}-key.pem',
|
|
|
|
{% endfor %}]"
|
2019-05-02 21:24:21 +00:00
|
|
|
delegate_to: "{{ groups['etcd'][0] }}"
|
2018-10-29 10:45:32 +00:00
|
|
|
when:
|
|
|
|
- inventory_hostname in groups['etcd']
|
|
|
|
- inventory_hostname != groups['etcd'][0]
|
2022-09-09 08:29:22 +00:00
|
|
|
- kube_network_plugin in ["calico", "flannel", "canal", "cilium"] or cilium_deploy_additionally | default(false) | bool
|
|
|
|
- kube_network_plugin != "calico" or calico_datastore == "etcd"
|
2016-11-09 10:44:41 +00:00
|
|
|
notify: set etcd_secret_changed
|
|
|
|
|
2021-02-09 09:53:22 +00:00
|
|
|
- name: Gen_certs | Write node certs to other etcd nodes
|
2018-08-24 09:35:31 +00:00
|
|
|
copy:
|
2018-09-27 09:12:02 +00:00
|
|
|
dest: "{{ item.item }}"
|
|
|
|
content: "{{ item.content | b64decode }}"
|
|
|
|
group: "{{ etcd_cert_group }}"
|
2022-06-17 08:34:32 +00:00
|
|
|
owner: "{{ etcd_owner }}"
|
2018-09-27 09:12:02 +00:00
|
|
|
mode: 0640
|
2021-02-09 09:53:22 +00:00
|
|
|
with_items: "{{ etcd_master_node_certs.results }}"
|
2018-10-29 10:45:32 +00:00
|
|
|
when:
|
|
|
|
- inventory_hostname in groups['etcd']
|
|
|
|
- inventory_hostname != groups['etcd'][0]
|
2022-09-09 08:29:22 +00:00
|
|
|
- kube_network_plugin in ["calico", "flannel", "canal", "cilium"] or cilium_deploy_additionally | default(false) | bool
|
|
|
|
- kube_network_plugin != "calico" or calico_datastore == "etcd"
|
2018-12-04 18:35:44 +00:00
|
|
|
loop_control:
|
|
|
|
label: "{{ item.item }}"
|
2018-08-24 09:35:31 +00:00
|
|
|
|
2022-09-09 08:29:22 +00:00
|
|
|
- include_tasks: gen_nodes_certs_script.yml
|
|
|
|
when:
|
|
|
|
- inventory_hostname in groups['kube_control_plane'] and
|
2018-10-29 10:45:32 +00:00
|
|
|
sync_certs|default(false) and inventory_hostname not in groups['etcd']
|
|
|
|
|
2022-09-09 08:29:22 +00:00
|
|
|
- include_tasks: gen_nodes_certs_script.yml
|
|
|
|
when:
|
|
|
|
- kube_network_plugin in ["calico", "flannel", "canal", "cilium"] or cilium_deploy_additionally | default(false) | bool
|
|
|
|
- kube_network_plugin != "calico" or calico_datastore == "etcd"
|
|
|
|
- inventory_hostname in groups['k8s_cluster'] and
|
2018-09-27 09:12:02 +00:00
|
|
|
sync_certs|default(false) and inventory_hostname not in groups['etcd']
|
2018-10-29 10:45:32 +00:00
|
|
|
|
|
|
|
- name: Gen_certs | check certificate permissions
|
|
|
|
file:
|
|
|
|
path: "{{ etcd_cert_dir }}"
|
|
|
|
group: "{{ etcd_cert_group }}"
|
|
|
|
state: directory
|
2022-06-17 08:34:32 +00:00
|
|
|
owner: "{{ etcd_owner }}"
|
2020-12-09 08:48:49 +00:00
|
|
|
mode: "{{ etcd_cert_dir_mode }}"
|
2018-10-29 10:45:32 +00:00
|
|
|
recurse: yes
|