2016-11-09 10:44:41 +00:00
|
|
|
---
|
2021-02-09 09:53:22 +00:00
|
|
|
- name: "Check_certs | Register certs that have already been generated on first etcd node"
|
2017-03-03 13:21:01 +00:00
|
|
|
find:
|
|
|
|
paths: "{{ etcd_cert_dir }}"
|
2021-02-09 09:53:22 +00:00
|
|
|
patterns: "ca.pem,node*.pem,member*.pem,admin*.pem"
|
2017-03-15 11:00:42 +00:00
|
|
|
get_checksum: true
|
2019-05-02 21:24:21 +00:00
|
|
|
delegate_to: "{{ groups['etcd'][0] }}"
|
2016-11-09 10:44:41 +00:00
|
|
|
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
|
|
|
|
2021-02-09 09:53:22 +00:00
|
|
|
- name: "Check certs | Register ca and etcd admin/member certs on etcd hosts"
|
2016-11-09 10:44:41 +00:00
|
|
|
stat:
|
2016-12-27 15:26:22 +00:00
|
|
|
path: "{{ etcd_cert_dir }}/{{ item }}"
|
2021-02-10 13:36:59 +00:00
|
|
|
get_attributes: no
|
|
|
|
get_checksum: yes
|
|
|
|
get_mime: no
|
2021-02-09 09:53:22 +00:00
|
|
|
register: etcd_member_certs
|
|
|
|
when: inventory_hostname in groups['etcd']
|
2016-12-13 09:03:35 +00:00
|
|
|
with_items:
|
|
|
|
- ca.pem
|
2021-02-09 09:53:22 +00:00
|
|
|
- member-{{ inventory_hostname }}.pem
|
|
|
|
- member-{{ inventory_hostname }}-key.pem
|
|
|
|
- admin-{{ inventory_hostname }}.pem
|
|
|
|
- admin-{{ inventory_hostname }}-key.pem
|
|
|
|
|
|
|
|
- name: "Check certs | Register ca and etcd node certs on kubernetes hosts"
|
|
|
|
stat:
|
|
|
|
path: "{{ etcd_cert_dir }}/{{ item }}"
|
|
|
|
register: etcd_node_certs
|
|
|
|
when: (('calico-rr' in groups and inventory_hostname in groups['calico-rr']) or
|
|
|
|
inventory_hostname in groups['k8s-cluster'])
|
|
|
|
with_items:
|
|
|
|
- ca.pem
|
|
|
|
- node-{{ inventory_hostname }}.pem
|
2016-12-13 09:03:35 +00:00
|
|
|
- node-{{ inventory_hostname }}-key.pem
|
2016-11-09 10:44:41 +00:00
|
|
|
|
2021-02-09 09:53:22 +00:00
|
|
|
- name: "Check_certs | Set 'gen_certs' to true if expected certificates are not on the first etcd node"
|
2017-03-03 13:21:01 +00:00
|
|
|
set_fact:
|
|
|
|
gen_certs: true
|
2021-02-09 09:53:22 +00:00
|
|
|
when: force_etcd_cert_refresh or not item in etcdcert_master.files|map(attribute='path') | list
|
2017-03-03 13:21:01 +00:00
|
|
|
run_once: true
|
2019-04-24 05:20:00 +00:00
|
|
|
with_items: "{{ expected_files }}"
|
|
|
|
vars:
|
|
|
|
expected_files: >-
|
2020-06-29 19:39:59 +00:00
|
|
|
['{{ etcd_cert_dir }}/ca.pem',
|
2021-02-09 09:53:22 +00:00
|
|
|
{% set etcd_members = groups['etcd'] %}
|
|
|
|
{% for host in etcd_members %}
|
|
|
|
'{{ etcd_cert_dir }}/admin-{{ host }}.pem',
|
2020-06-29 19:39:59 +00:00
|
|
|
'{{ etcd_cert_dir }}/admin-{{ host }}-key.pem',
|
2021-02-09 09:53:22 +00:00
|
|
|
'{{ etcd_cert_dir }}/member-{{ host }}.pem',
|
|
|
|
'{{ etcd_cert_dir }}/member-{{ host }}-key.pem',
|
|
|
|
{% endfor %}
|
|
|
|
{% set k8s_nodes = groups['k8s-cluster']|union(groups['calico-rr']|default([]))|unique|sort %}
|
|
|
|
{% for host in k8s_nodes %}
|
|
|
|
'{{ etcd_cert_dir }}/node-{{ host }}.pem',
|
|
|
|
'{{ etcd_cert_dir }}/node-{{ host }}-key.pem'
|
2020-06-29 19:39:59 +00:00
|
|
|
{% if not loop.last %}{{','}}{% endif %}
|
|
|
|
{% endfor %}]
|
2017-03-03 13:21:01 +00:00
|
|
|
|
2021-02-09 09:53:22 +00:00
|
|
|
- name: "Check_certs | Set 'gen_master_certs' object to track whether member and admin certs exist on first etcd node"
|
2020-03-25 19:46:25 +00:00
|
|
|
set_fact:
|
|
|
|
gen_master_certs: |-
|
|
|
|
{
|
2021-02-09 09:53:22 +00:00
|
|
|
{% set etcd_members = groups['etcd'] -%}
|
2020-03-25 19:46:25 +00:00
|
|
|
{% set existing_certs = etcdcert_master.files|map(attribute='path')|list|sort %}
|
2021-02-09 09:53:22 +00:00
|
|
|
{% for host in etcd_members -%}
|
|
|
|
{% set member_cert = "%s/member-%s.pem"|format(etcd_cert_dir, host) %}
|
|
|
|
{% set member_key = "%s/member-%s-key.pem"|format(etcd_cert_dir, host) %}
|
|
|
|
{% set admin_cert = "%s/admin-%s.pem"|format(etcd_cert_dir, host) %}
|
|
|
|
{% set admin_key = "%s/admin-%s-key.pem"|format(etcd_cert_dir, host) %}
|
|
|
|
{% if force_etcd_cert_refresh -%}
|
|
|
|
"{{ host }}": True,
|
|
|
|
{% elif member_cert in existing_certs and member_key in existing_certs and admin_cert in existing_certs and admin_key in existing_certs -%}
|
2020-03-25 19:46:25 +00:00
|
|
|
"{{ host }}": False,
|
|
|
|
{% else -%}
|
|
|
|
"{{ host }}": True,
|
|
|
|
{% endif -%}
|
|
|
|
{% endfor %}
|
|
|
|
}
|
|
|
|
run_once: true
|
|
|
|
|
2021-02-09 09:53:22 +00:00
|
|
|
- name: "Check_certs | Set 'gen_node_certs' object to track whether node certs exist on first etcd node"
|
2017-03-03 13:21:01 +00:00
|
|
|
set_fact:
|
|
|
|
gen_node_certs: |-
|
|
|
|
{
|
2021-02-09 09:53:22 +00:00
|
|
|
{% set k8s_nodes = groups['k8s-cluster']|union(groups['calico-rr']|default([]))|unique|sort -%}
|
2017-03-03 13:21:01 +00:00
|
|
|
{% set existing_certs = etcdcert_master.files|map(attribute='path')|list|sort %}
|
2021-02-09 09:53:22 +00:00
|
|
|
{% for host in k8s_nodes -%}
|
|
|
|
{% set host_cert = "%s/node-%s.pem"|format(etcd_cert_dir, host) %}
|
|
|
|
{% set host_key = "%s/node-%s-key.pem"|format(etcd_cert_dir, host) %}
|
|
|
|
{% if force_etcd_cert_refresh -%}
|
|
|
|
"{{ host }}": True,
|
|
|
|
{% elif host_cert in existing_certs and host_key in existing_certs -%}
|
2017-03-03 13:21:01 +00:00
|
|
|
"{{ host }}": False,
|
|
|
|
{% else -%}
|
|
|
|
"{{ host }}": True,
|
|
|
|
{% endif -%}
|
|
|
|
{% endfor %}
|
|
|
|
}
|
|
|
|
run_once: true
|
|
|
|
|
2021-02-09 09:53:22 +00:00
|
|
|
- name: "Check_certs | Set 'etcd_member_requires_sync' to true if ca or member/admin cert and key don't exist on etcd member or checksum doesn't match"
|
|
|
|
set_fact:
|
|
|
|
etcd_member_requires_sync: true
|
|
|
|
when:
|
|
|
|
- inventory_hostname in groups['etcd']
|
|
|
|
- (not etcd_member_certs.results[0].stat.exists|default(false)) or
|
|
|
|
(not etcd_member_certs.results[1].stat.exists|default(false)) or
|
|
|
|
(not etcd_member_certs.results[2].stat.exists|default(false)) or
|
|
|
|
(not etcd_member_certs.results[3].stat.exists|default(false)) or
|
|
|
|
(not etcd_member_certs.results[4].stat.exists|default(false)) or
|
|
|
|
(etcd_member_certs.results[0].stat.checksum|default('') != etcdcert_master.files|selectattr("path", "equalto", etcd_member_certs.results[0].stat.path)|map(attribute="checksum")|first|default('')) or
|
|
|
|
(etcd_member_certs.results[1].stat.checksum|default('') != etcdcert_master.files|selectattr("path", "equalto", etcd_member_certs.results[1].stat.path)|map(attribute="checksum")|first|default('')) or
|
|
|
|
(etcd_member_certs.results[2].stat.checksum|default('') != etcdcert_master.files|selectattr("path", "equalto", etcd_member_certs.results[2].stat.path)|map(attribute="checksum")|first|default('')) or
|
|
|
|
(etcd_member_certs.results[3].stat.checksum|default('') != etcdcert_master.files|selectattr("path", "equalto", etcd_member_certs.results[3].stat.path)|map(attribute="checksum")|first|default('')) or
|
|
|
|
(etcd_member_certs.results[4].stat.checksum|default('') != etcdcert_master.files|selectattr("path", "equalto", etcd_member_certs.results[4].stat.path)|map(attribute="checksum")|first|default(''))
|
|
|
|
|
|
|
|
- name: "Check_certs | Set 'kubernetes_host_requires_sync' to true if ca or node cert and key don't exist on kubernetes host or checksum doesn't match"
|
|
|
|
set_fact:
|
|
|
|
kubernetes_host_requires_sync: 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']
|
|
|
|
- (not etcd_node_certs.results[0].stat.exists|default(false)) or
|
|
|
|
(not etcd_node_certs.results[1].stat.exists|default(false)) or
|
|
|
|
(not etcd_node_certs.results[2].stat.exists|default(false)) or
|
|
|
|
(etcd_node_certs.results[0].stat.checksum|default('') != etcdcert_master.files|selectattr("path", "equalto", etcd_node_certs.results[0].stat.path)|map(attribute="checksum")|first|default('')) or
|
|
|
|
(etcd_node_certs.results[1].stat.checksum|default('') != etcdcert_master.files|selectattr("path", "equalto", etcd_node_certs.results[1].stat.path)|map(attribute="checksum")|first|default('')) or
|
|
|
|
(etcd_node_certs.results[2].stat.checksum|default('') != etcdcert_master.files|selectattr("path", "equalto", etcd_node_certs.results[2].stat.path)|map(attribute="checksum")|first|default(''))
|
|
|
|
|
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:
|
2021-02-09 09:53:22 +00:00
|
|
|
- etcd_member_requires_sync|default(false) or
|
|
|
|
kubernetes_host_requires_sync|default(false) or
|
|
|
|
(inventory_hostname in gen_master_certs and gen_master_certs[inventory_hostname]) or
|
|
|
|
(inventory_hostname in gen_node_certs and gen_node_certs[inventory_hostname])
|