c12s-kubespray/roles/etcd/tasks/gen_certs_script.yml

132 lines
4.3 KiB
YAML
Raw Normal View History

2016-11-09 10:44:41 +00:00
---
- name: Gen_certs | create etcd cert dir
file:
path: "{{ etcd_cert_dir }}"
group: "{{ etcd_cert_group }}"
state: directory
2017-03-14 14:23:29 +00:00
owner: kube
mode: 0700
recurse: yes
2016-11-09 10:44:41 +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
owner: root
2017-03-14 14:23:29 +00:00
mode: 0700
run_once: yes
when: inventory_hostname == groups['etcd'][0]
delegate_to: "{{groups['etcd'][0]}}"
2016-11-09 10:44:41 +00:00
- name: "Gen_certs | create etcd cert dir (on {{groups['etcd'][0]}})"
2016-11-09 10:44:41 +00:00
file:
path: "{{ etcd_cert_dir }}"
group: "{{ etcd_cert_group }}"
state: directory
2017-03-14 14:23:29 +00:00
owner: kube
recurse: yes
2017-03-14 14:23:29 +00:00
mode: 0700
run_once: yes
when: inventory_hostname == groups['etcd'][0]
delegate_to: "{{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"
run_once: yes
delegate_to: "{{groups['etcd'][0]}}"
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
copy:
src: "make-ssl-etcd.sh"
dest: "{{ etcd_script_dir }}/make-ssl-etcd.sh"
mode: 0700
run_once: yes
delegate_to: "{{groups['etcd'][0]}}"
when:
- gen_certs|default(false)
- inventory_hostname == groups['etcd'][0]
2017-03-14 14:23:29 +00:00
2016-11-09 10:44:41 +00:00
- name: Gen_certs | run cert generation script
command: "bash -x {{ etcd_script_dir }}/make-ssl-etcd.sh -f {{ etcd_config_dir }}/openssl.conf -d {{ etcd_cert_dir }}"
environment:
- MASTERS: "{% for m in groups['etcd'] %}
{% if gen_node_certs[m] %}
{{ m }}
{% endif %}
{% endfor %}"
- HOSTS: "{% for h in (groups['k8s-cluster'] + groups['calico-rr']|default([]))|unique %}
{% if gen_node_certs[h] %}
{{ h }}
{% endif %}
{% endfor %}"
2016-11-09 10:44:41 +00:00
run_once: yes
delegate_to: "{{groups['etcd'][0]}}"
when:
- gen_certs|default(false)
- inventory_hostname == groups['etcd'][0]
2016-11-09 10:44:41 +00:00
notify: set etcd_secret_changed
- name: Gen_certs | Gather etcd master certs
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 %}]"
- "[{% for node in (groups['k8s-cluster'] + groups['calico-rr']|default([]))|unique %}
'{{ etcd_cert_dir }}/node-{{ node }}.pem',
'{{ etcd_cert_dir }}/node-{{ node }}-key.pem',
{% endfor %}]"
2016-11-09 10:44:41 +00:00
delegate_to: "{{groups['etcd'][0]}}"
when: inventory_hostname in groups['etcd'] and sync_certs|default(false) and
inventory_hostname != groups['etcd'][0]
2016-11-09 10:44:41 +00:00
notify: set etcd_secret_changed
- name: Gen_certs | Gather etcd node certs
2018-09-27 09:12:02 +00:00
slurp:
src: "{{ item }}"
register: etcd_node_certs
with_items:
- "{{ etcd_cert_dir }}/ca.pem"
- "{{ etcd_cert_dir }}/node-{{ inventory_hostname }}.pem"
- "{{ etcd_cert_dir }}/node-{{ inventory_hostname }}-key.pem"
2016-11-09 10:44:41 +00:00
delegate_to: "{{groups['etcd'][0]}}"
when: (('calico-rr' in groups and inventory_hostname in groups['calico-rr']) or
inventory_hostname in groups['k8s-cluster']) and
sync_certs|default(false) and inventory_hostname not in groups['etcd']
2016-11-09 10:44:41 +00:00
notify: set etcd_secret_changed
2018-09-27 09:12:02 +00:00
- name: Gen_certs | Write etcd master certs
copy:
2018-09-27 09:12:02 +00:00
dest: "{{ item.item }}"
content: "{{ item.content | b64decode }}"
group: "{{ etcd_cert_group }}"
owner: kube
mode: 0640
with_items: "{{ etcd_master_certs.results }}"
when: inventory_hostname in groups['etcd'] and sync_certs|default(false) and
inventory_hostname != groups['etcd'][0]
2018-09-27 09:12:02 +00:00
- name: Gen_certs | Write etcd node certs
copy:
dest: "{{ item.item }}"
content: "{{ item.content | b64decode }}"
group: "{{ etcd_cert_group }}"
owner: kube
2018-09-27 09:12:02 +00:00
mode: 0640
with_items: "{{ etcd_node_certs.results }}"
when: (('calico-rr' in groups and inventory_hostname in groups['calico-rr']) or
inventory_hostname in groups['k8s-cluster']) and
sync_certs|default(false) and inventory_hostname not in groups['etcd']