2016-11-09 18:44:41 +08:00
|
|
|
---
|
2017-01-15 13:24:34 +08:00
|
|
|
- name: Gen_certs | create etcd cert dir
|
|
|
|
file:
|
2017-02-18 05:22:34 +08:00
|
|
|
path: "{{ etcd_cert_dir }}"
|
|
|
|
group: "{{ etcd_cert_group }}"
|
|
|
|
state: directory
|
2017-03-14 22:23:29 +08:00
|
|
|
owner: kube
|
|
|
|
mode: 0700
|
2017-02-18 05:22:34 +08:00
|
|
|
recurse: yes
|
2016-11-09 18:44:41 +08:00
|
|
|
|
2017-01-19 04:06:50 +08:00
|
|
|
- name: "Gen_certs | create etcd script dir (on {{groups['etcd'][0]}})"
|
2016-11-09 18:44:41 +08:00
|
|
|
file:
|
|
|
|
path: "{{ etcd_script_dir }}"
|
|
|
|
state: directory
|
2017-02-06 20:58:54 +08:00
|
|
|
owner: root
|
2017-03-14 22:23:29 +08:00
|
|
|
mode: 0700
|
2017-01-15 13:24:34 +08:00
|
|
|
run_once: yes
|
2018-04-02 00:58:08 +08:00
|
|
|
when: inventory_hostname == groups['etcd'][0]
|
2017-01-15 13:24:34 +08:00
|
|
|
delegate_to: "{{groups['etcd'][0]}}"
|
2016-11-09 18:44:41 +08:00
|
|
|
|
2017-01-19 04:06:50 +08:00
|
|
|
- name: "Gen_certs | create etcd cert dir (on {{groups['etcd'][0]}})"
|
2016-11-09 18:44:41 +08:00
|
|
|
file:
|
2017-02-18 05:22:34 +08:00
|
|
|
path: "{{ etcd_cert_dir }}"
|
|
|
|
group: "{{ etcd_cert_group }}"
|
|
|
|
state: directory
|
2017-03-14 22:23:29 +08:00
|
|
|
owner: kube
|
2017-02-18 05:22:34 +08:00
|
|
|
recurse: yes
|
2017-03-14 22:23:29 +08:00
|
|
|
mode: 0700
|
2017-01-15 13:24:34 +08:00
|
|
|
run_once: yes
|
2018-04-02 00:58:08 +08:00
|
|
|
when: inventory_hostname == groups['etcd'][0]
|
2017-01-15 13:24:34 +08:00
|
|
|
delegate_to: "{{groups['etcd'][0]}}"
|
2016-11-09 18:44:41 +08: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]}}"
|
2018-04-02 00:58:08 +08:00
|
|
|
when:
|
|
|
|
- gen_certs|default(false)
|
|
|
|
- inventory_hostname == groups['etcd'][0]
|
2016-11-09 18:44:41 +08:00
|
|
|
|
|
|
|
- name: Gen_certs | copy certs generation script
|
2018-10-09 19:43:30 +08:00
|
|
|
template:
|
|
|
|
src: "make-ssl-etcd.sh.j2"
|
2016-11-09 18:44:41 +08:00
|
|
|
dest: "{{ etcd_script_dir }}/make-ssl-etcd.sh"
|
|
|
|
mode: 0700
|
|
|
|
run_once: yes
|
|
|
|
delegate_to: "{{groups['etcd'][0]}}"
|
2018-04-02 00:58:08 +08:00
|
|
|
when:
|
|
|
|
- gen_certs|default(false)
|
|
|
|
- inventory_hostname == groups['etcd'][0]
|
2017-03-14 22:23:29 +08:00
|
|
|
|
2016-11-09 18:44:41 +08:00
|
|
|
- name: Gen_certs | run cert generation script
|
2017-03-03 21:21:01 +08:00
|
|
|
command: "bash -x {{ etcd_script_dir }}/make-ssl-etcd.sh -f {{ etcd_config_dir }}/openssl.conf -d {{ etcd_cert_dir }}"
|
2016-12-13 17:03:35 +08:00
|
|
|
environment:
|
|
|
|
- MASTERS: "{% for m in groups['etcd'] %}
|
2017-03-03 21:21:01 +08:00
|
|
|
{% if gen_node_certs[m] %}
|
2016-12-13 17:03:35 +08:00
|
|
|
{{ m }}
|
|
|
|
{% endif %}
|
|
|
|
{% endfor %}"
|
2017-01-05 17:16:11 +08:00
|
|
|
- HOSTS: "{% for h in (groups['k8s-cluster'] + groups['calico-rr']|default([]))|unique %}
|
2017-03-03 21:21:01 +08:00
|
|
|
{% if gen_node_certs[h] %}
|
2016-12-13 17:03:35 +08:00
|
|
|
{{ h }}
|
|
|
|
{% endif %}
|
|
|
|
{% endfor %}"
|
2016-11-09 18:44:41 +08:00
|
|
|
run_once: yes
|
|
|
|
delegate_to: "{{groups['etcd'][0]}}"
|
2018-04-02 00:58:08 +08:00
|
|
|
when:
|
|
|
|
- gen_certs|default(false)
|
|
|
|
- inventory_hostname == groups['etcd'][0]
|
2016-11-09 18:44:41 +08:00
|
|
|
notify: set etcd_secret_changed
|
|
|
|
|
|
|
|
- name: Gen_certs | Gather etcd master certs
|
2018-09-27 17:12:02 +08: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 18:44:41 +08:00
|
|
|
delegate_to: "{{groups['etcd'][0]}}"
|
2018-10-29 18:45:32 +08:00
|
|
|
when:
|
|
|
|
- inventory_hostname in groups['etcd']
|
|
|
|
- sync_certs|default(false)
|
|
|
|
- inventory_hostname != groups['etcd'][0]
|
2016-11-09 18:44:41 +08:00
|
|
|
notify: set etcd_secret_changed
|
|
|
|
|
2018-09-27 17:12:02 +08:00
|
|
|
- name: Gen_certs | Write etcd master certs
|
2018-08-24 17:35:31 +08:00
|
|
|
copy:
|
2018-09-27 17:12:02 +08:00
|
|
|
dest: "{{ item.item }}"
|
|
|
|
content: "{{ item.content | b64decode }}"
|
|
|
|
group: "{{ etcd_cert_group }}"
|
|
|
|
owner: kube
|
|
|
|
mode: 0640
|
|
|
|
with_items: "{{ etcd_master_certs.results }}"
|
2018-10-29 18:45:32 +08:00
|
|
|
when:
|
|
|
|
- inventory_hostname in groups['etcd']
|
|
|
|
- sync_certs|default(false)
|
|
|
|
- inventory_hostname != groups['etcd'][0]
|
2018-08-24 17:35:31 +08:00
|
|
|
|
2018-10-29 18:45:32 +08:00
|
|
|
- set_fact:
|
|
|
|
my_etcd_node_certs: ['ca.pem',
|
|
|
|
'node-{{ inventory_hostname }}.pem',
|
|
|
|
'node-{{ inventory_hostname }}-key.pem']
|
|
|
|
tags:
|
|
|
|
- facts
|
|
|
|
|
|
|
|
- name: "Check_certs | Set 'sync_certs' to true on nodes"
|
|
|
|
set_fact:
|
|
|
|
sync_certs: true
|
|
|
|
when: (('calico-rr' in groups and inventory_hostname in groups['calico-rr']) or
|
|
|
|
inventory_hostname in groups['k8s-cluster']) and
|
|
|
|
inventory_hostname not in groups['etcd']
|
|
|
|
with_items:
|
|
|
|
- "{{ my_etcd_node_certs }}"
|
|
|
|
|
|
|
|
- name: Gen_certs | Gather node certs
|
|
|
|
shell: "tar cfz - -C {{ etcd_cert_dir }} -T /dev/stdin <<< {{ my_etcd_node_certs|join(' ') }} | base64 --wrap=0"
|
|
|
|
args:
|
|
|
|
executable: /bin/bash
|
|
|
|
warn: false
|
|
|
|
no_log: true
|
|
|
|
register: etcd_node_certs
|
|
|
|
check_mode: no
|
|
|
|
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']
|
|
|
|
|
|
|
|
- name: Gen_certs | Copy certs on nodes
|
|
|
|
shell: "base64 -d <<< '{{etcd_node_certs.stdout|quote}}' | tar xz -C {{ etcd_cert_dir }}"
|
|
|
|
args:
|
|
|
|
executable: /bin/bash
|
|
|
|
no_log: true
|
|
|
|
changed_when: false
|
|
|
|
check_mode: no
|
2018-09-27 17:12:02 +08:00
|
|
|
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']
|
2018-10-29 18:45:32 +08:00
|
|
|
notify: set etcd_secret_changed
|
|
|
|
|
|
|
|
- name: Gen_certs | check certificate permissions
|
|
|
|
file:
|
|
|
|
path: "{{ etcd_cert_dir }}"
|
|
|
|
group: "{{ etcd_cert_group }}"
|
|
|
|
state: directory
|
|
|
|
owner: kube
|
|
|
|
mode: 0640
|
|
|
|
recurse: yes
|