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
|
|
|
|
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
|
|
|
|
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]}}"
|
|
|
|
when: gen_certs|default(false)
|
|
|
|
|
|
|
|
- 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)
|
|
|
|
|
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]}}"
|
|
|
|
when: gen_certs|default(false)
|
|
|
|
notify: set etcd_secret_changed
|
|
|
|
|
|
|
|
- set_fact:
|
2016-12-13 17:03:35 +08:00
|
|
|
all_master_certs: "['ca-key.pem',
|
|
|
|
{% for node in groups['etcd'] %}
|
|
|
|
'admin-{{ node }}.pem',
|
|
|
|
'admin-{{ node }}-key.pem',
|
|
|
|
'member-{{ node }}.pem',
|
|
|
|
'member-{{ node }}-key.pem',
|
|
|
|
{% endfor %}]"
|
|
|
|
my_master_certs: ['ca-key.pem',
|
2017-08-24 17:09:52 +08:00
|
|
|
'admin-{{ inventory_hostname }}.pem',
|
|
|
|
'admin-{{ inventory_hostname }}-key.pem',
|
|
|
|
'member-{{ inventory_hostname }}.pem',
|
|
|
|
'member-{{ inventory_hostname }}-key.pem']
|
2016-12-13 17:03:35 +08:00
|
|
|
all_node_certs: "['ca.pem',
|
2017-01-05 17:16:11 +08:00
|
|
|
{% for node in (groups['k8s-cluster'] + groups['calico-rr']|default([]))|unique %}
|
2016-12-13 17:03:35 +08:00
|
|
|
'node-{{ node }}.pem',
|
|
|
|
'node-{{ node }}-key.pem',
|
|
|
|
{% endfor %}]"
|
|
|
|
my_node_certs: ['ca.pem', 'node-{{ inventory_hostname }}.pem', 'node-{{ inventory_hostname }}-key.pem']
|
2016-12-08 21:36:00 +08:00
|
|
|
tags: facts
|
2016-11-09 18:44:41 +08:00
|
|
|
|
|
|
|
- name: Gen_certs | Gather etcd master certs
|
2016-12-30 17:55:26 +08:00
|
|
|
shell: "tar cfz - -C {{ etcd_cert_dir }} -T /dev/stdin <<< {{ my_master_certs|join(' ') }} {{ all_node_certs|join(' ') }} | base64 --wrap=0"
|
|
|
|
args:
|
|
|
|
executable: /bin/bash
|
2016-11-09 18:44:41 +08:00
|
|
|
register: etcd_master_cert_data
|
2017-02-17 05:43:49 +08:00
|
|
|
no_log: true
|
2017-02-07 02:13:21 +08:00
|
|
|
check_mode: no
|
2016-11-09 18:44:41 +08:00
|
|
|
delegate_to: "{{groups['etcd'][0]}}"
|
2016-12-27 23:26:22 +08:00
|
|
|
when: inventory_hostname in groups['etcd'] and sync_certs|default(false) and
|
|
|
|
inventory_hostname != groups['etcd'][0]
|
2016-11-09 18:44:41 +08:00
|
|
|
notify: set etcd_secret_changed
|
|
|
|
|
|
|
|
- name: Gen_certs | Gather etcd node certs
|
2016-12-30 17:55:26 +08:00
|
|
|
shell: "tar cfz - -C {{ etcd_cert_dir }} -T /dev/stdin <<< {{ my_node_certs|join(' ') }} | base64 --wrap=0"
|
|
|
|
args:
|
|
|
|
executable: /bin/bash
|
2016-11-09 18:44:41 +08:00
|
|
|
register: etcd_node_cert_data
|
2017-02-17 05:43:49 +08:00
|
|
|
no_log: true
|
2017-02-07 02:13:21 +08:00
|
|
|
check_mode: no
|
2016-11-09 18:44:41 +08:00
|
|
|
delegate_to: "{{groups['etcd'][0]}}"
|
2017-01-05 17:16:11 +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']
|
2016-11-09 18:44:41 +08:00
|
|
|
notify: set etcd_secret_changed
|
|
|
|
|
2017-08-24 17:09:52 +08:00
|
|
|
# NOTE(mattymo): Use temporary file to copy master certs because we have a ~200k
|
|
|
|
# char limit when using shell command
|
|
|
|
|
|
|
|
# FIXME(mattymo): Use tempfile module in ansible 2.3
|
|
|
|
- name: Gen_certs | Prepare tempfile for unpacking certs
|
|
|
|
shell: mktemp /tmp/certsXXXXX.tar.gz
|
|
|
|
register: cert_tempfile
|
2017-03-14 22:23:29 +08:00
|
|
|
when: inventory_hostname in groups['etcd'] and sync_certs|default(false) and
|
2017-08-24 17:09:52 +08:00
|
|
|
inventory_hostname != groups['etcd'][0]
|
2017-03-14 22:23:29 +08:00
|
|
|
|
2017-08-24 17:09:52 +08:00
|
|
|
- name: Gen_certs | Write master certs to tempfile
|
|
|
|
copy:
|
|
|
|
content: "{{etcd_master_cert_data.stdout}}"
|
|
|
|
dest: "{{cert_tempfile.stdout}}"
|
|
|
|
owner: root
|
|
|
|
mode: "0600"
|
2016-11-09 18:44:41 +08:00
|
|
|
when: inventory_hostname in groups['etcd'] and sync_certs|default(false) and
|
2017-03-15 19:00:42 +08:00
|
|
|
inventory_hostname != groups['etcd'][0]
|
|
|
|
|
|
|
|
- name: Gen_certs | Unpack certs on masters
|
2017-03-03 21:21:01 +08:00
|
|
|
shell: "base64 -d < {{ cert_tempfile.stdout }} | tar xz -C {{ etcd_cert_dir }}"
|
2017-03-15 19:00:42 +08:00
|
|
|
no_log: true
|
|
|
|
changed_when: false
|
|
|
|
check_mode: no
|
2017-03-03 21:21:01 +08:00
|
|
|
when: inventory_hostname in groups['etcd'] and sync_certs|default(false) and
|
2017-03-15 19:00:42 +08:00
|
|
|
inventory_hostname != groups['etcd'][0]
|
|
|
|
notify: set secret_changed
|
|
|
|
|
|
|
|
- name: Gen_certs | Cleanup tempfile
|
|
|
|
file:
|
|
|
|
path: "{{cert_tempfile.stdout}}"
|
|
|
|
state: absent
|
2017-03-03 21:21:01 +08:00
|
|
|
when: inventory_hostname in groups['etcd'] and sync_certs|default(false) and
|
2017-03-15 19:00:42 +08:00
|
|
|
inventory_hostname != groups['etcd'][0]
|
2016-11-09 18:44:41 +08:00
|
|
|
|
|
|
|
- name: Gen_certs | Copy certs on nodes
|
2016-12-30 17:55:26 +08:00
|
|
|
shell: "base64 -d <<< '{{etcd_node_cert_data.stdout|quote}}' | tar xz -C {{ etcd_cert_dir }}"
|
|
|
|
args:
|
|
|
|
executable: /bin/bash
|
2016-11-09 18:44:41 +08:00
|
|
|
changed_when: false
|
2016-12-27 23:26:22 +08:00
|
|
|
when: sync_certs|default(false) and
|
|
|
|
inventory_hostname not in groups['etcd']
|
2016-11-09 18:44:41 +08:00
|
|
|
|
|
|
|
- name: Gen_certs | check certificate permissions
|
|
|
|
file:
|
2017-02-18 05:22:34 +08:00
|
|
|
path: "{{ etcd_cert_dir }}"
|
|
|
|
group: "{{ etcd_cert_group }}"
|
|
|
|
state: directory
|
|
|
|
owner: kube
|
2017-03-14 22:23:29 +08:00
|
|
|
mode: "u=rwX,g-rwx,o-rwx"
|
2017-02-18 05:22:34 +08:00
|
|
|
recurse: yes
|
2016-11-09 18:44:41 +08:00
|
|
|
|
2016-11-11 23:39:22 +08:00
|
|
|
- name: Gen_certs | target ca-certificate store file
|
2016-11-09 18:44:41 +08:00
|
|
|
set_fact:
|
2016-11-11 23:39:22 +08:00
|
|
|
ca_cert_path: |-
|
2016-11-09 18:44:41 +08:00
|
|
|
{% if ansible_os_family == "Debian" -%}
|
2016-11-11 23:39:22 +08:00
|
|
|
/usr/local/share/ca-certificates/etcd-ca.crt
|
2016-11-09 18:44:41 +08:00
|
|
|
{%- elif ansible_os_family == "RedHat" -%}
|
2016-11-11 23:39:22 +08:00
|
|
|
/etc/pki/ca-trust/source/anchors/etcd-ca.crt
|
2017-01-05 23:32:08 +08:00
|
|
|
{%- elif ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] -%}
|
2016-11-11 23:39:22 +08:00
|
|
|
/etc/ssl/certs/etcd-ca.pem
|
2016-11-09 18:44:41 +08:00
|
|
|
{%- endif %}
|
2016-12-08 21:36:00 +08:00
|
|
|
tags: facts
|
2016-11-09 18:44:41 +08:00
|
|
|
|
|
|
|
- name: Gen_certs | add CA to trusted CA dir
|
|
|
|
copy:
|
|
|
|
src: "{{ etcd_cert_dir }}/ca.pem"
|
2016-11-11 23:39:22 +08:00
|
|
|
dest: "{{ ca_cert_path }}"
|
2016-11-09 18:44:41 +08:00
|
|
|
remote_src: true
|
|
|
|
register: etcd_ca_cert
|
|
|
|
|
2017-01-05 18:35:16 +08:00
|
|
|
- name: Gen_certs | update ca-certificates (Debian/Ubuntu/Container Linux by CoreOS)
|
2016-11-09 18:44:41 +08:00
|
|
|
command: update-ca-certificates
|
2017-02-17 00:25:03 +08:00
|
|
|
when: etcd_ca_cert.changed and ansible_os_family in ["Debian", "CoreOS", "Container Linux by CoreOS"]
|
2016-11-09 18:44:41 +08:00
|
|
|
|
2016-11-11 23:39:22 +08:00
|
|
|
- name: Gen_certs | update ca-certificates (RedHat)
|
2016-11-09 18:44:41 +08:00
|
|
|
command: update-ca-trust extract
|
|
|
|
when: etcd_ca_cert.changed and ansible_os_family == "RedHat"
|