2016-11-09 10:44:41 +00:00
|
|
|
---
|
2016-12-13 09:03:35 +00:00
|
|
|
- name: "Check_certs | check if all certs have already been generated on first master"
|
2017-03-03 13:21:01 +00:00
|
|
|
find:
|
|
|
|
paths: "{{ etcd_cert_dir }}"
|
|
|
|
patterns: "ca.pem,node*.pem"
|
2017-03-15 11:00:42 +00:00
|
|
|
get_checksum: true
|
2016-11-09 10:44:41 +00:00
|
|
|
delegate_to: "{{groups['etcd'][0]}}"
|
|
|
|
register: etcdcert_master
|
|
|
|
run_once: true
|
|
|
|
|
2016-12-13 09:03:35 +00:00
|
|
|
- name: "Check_certs | Set default value for 'sync_certs', 'gen_certs' and 'etcd_secret_changed' to false"
|
2016-11-09 10:44:41 +00:00
|
|
|
set_fact:
|
|
|
|
sync_certs: false
|
|
|
|
gen_certs: false
|
2016-12-13 09:03:35 +00:00
|
|
|
etcd_secret_changed: false
|
2016-11-09 10:44:41 +00:00
|
|
|
|
2017-03-03 13:21:01 +00:00
|
|
|
- name: "Check certs | check if a cert already exists on node"
|
2016-11-09 10:44:41 +00:00
|
|
|
stat:
|
2016-12-27 15:26:22 +00:00
|
|
|
path: "{{ etcd_cert_dir }}/{{ item }}"
|
2017-03-03 13:21:01 +00:00
|
|
|
register: etcdcert_node
|
2016-12-13 09:03:35 +00:00
|
|
|
with_items:
|
|
|
|
- ca.pem
|
|
|
|
- node-{{ inventory_hostname }}-key.pem
|
2016-11-09 10:44:41 +00:00
|
|
|
|
2017-03-03 13:21:01 +00:00
|
|
|
|
|
|
|
- name: "Check_certs | Set 'gen_certs' to true"
|
|
|
|
set_fact:
|
|
|
|
gen_certs: true
|
2017-10-20 07:25:57 +00:00
|
|
|
when: not item in etcdcert_master.files|map(attribute='path') | list
|
2017-03-03 13:21:01 +00:00
|
|
|
run_once: true
|
|
|
|
with_items: >-
|
|
|
|
['{{etcd_cert_dir}}/ca.pem',
|
|
|
|
{% set all_etcd_hosts = groups['k8s-cluster']|union(groups['etcd'])|union(groups['calico-rr']|default([]))|unique|sort %}
|
|
|
|
{% for host in all_etcd_hosts %}
|
|
|
|
'{{etcd_cert_dir}}/node-{{ host }}-key.pem'
|
|
|
|
{% if not loop.last %}{{','}}{% endif %}
|
|
|
|
{% endfor %}]
|
|
|
|
|
|
|
|
|
|
|
|
- name: "Check_certs | Set 'gen_node_certs' to true"
|
|
|
|
set_fact:
|
|
|
|
gen_node_certs: |-
|
|
|
|
{
|
|
|
|
{% set all_etcd_hosts = groups['k8s-cluster']|union(groups['etcd'])|union(groups['calico-rr']|default([]))|unique|sort -%}
|
|
|
|
{% set existing_certs = etcdcert_master.files|map(attribute='path')|list|sort %}
|
|
|
|
{% for host in all_etcd_hosts -%}
|
|
|
|
{% set host_cert = "%s/node-%s-key.pem"|format(etcd_cert_dir, host) %}
|
|
|
|
{% if host_cert in existing_certs -%}
|
|
|
|
"{{ host }}": False,
|
|
|
|
{% else -%}
|
|
|
|
"{{ host }}": True,
|
|
|
|
{% endif -%}
|
|
|
|
{% endfor %}
|
|
|
|
}
|
|
|
|
run_once: true
|
|
|
|
|
2016-11-09 10:44:41 +00:00
|
|
|
- name: "Check_certs | Set 'sync_certs' to true"
|
|
|
|
set_fact:
|
|
|
|
sync_certs: true
|
2018-10-16 06:47:04 +00:00
|
|
|
when:
|
|
|
|
- gen_node_certs[inventory_hostname] or
|
|
|
|
(not etcdcert_node.results[0].stat.exists|default(false)) or
|
|
|
|
(not etcdcert_node.results[1].stat.exists|default(false)) or
|
|
|
|
(etcdcert_node.results[1].stat.checksum|default('') != etcdcert_master.files|selectattr("path", "equalto", etcdcert_node.results[1].stat.path)|map(attribute="checksum")|first|default(''))
|