2016-04-07 15:08:39 +00:00
|
|
|
---
|
2016-05-13 13:08:28 +00:00
|
|
|
- name: "Check_certs | check if the certs have already been generated on first master"
|
2017-03-03 13:21:01 +00:00
|
|
|
find:
|
|
|
|
paths: "{{ kube_cert_dir }}"
|
|
|
|
patterns: "*.pem"
|
2017-03-15 11:00:42 +00:00
|
|
|
get_checksum: true
|
2016-04-11 07:33:08 +00:00
|
|
|
delegate_to: "{{groups['kube-master'][0]}}"
|
2016-04-07 15:08:39 +00:00
|
|
|
register: kubecert_master
|
|
|
|
run_once: true
|
|
|
|
|
2016-12-27 11:02:45 +00:00
|
|
|
- name: "Check_certs | Set default value for 'sync_certs', 'gen_certs', and 'secret_changed' to false"
|
2016-04-07 15:08:39 +00:00
|
|
|
set_fact:
|
|
|
|
sync_certs: false
|
|
|
|
gen_certs: false
|
2016-12-27 11:02:45 +00:00
|
|
|
secret_changed: false
|
2016-04-07 15:08:39 +00:00
|
|
|
|
2017-03-03 13:21:01 +00:00
|
|
|
- name: "Check certs | check if a cert already exists on node"
|
2016-04-07 15:08:39 +00:00
|
|
|
stat:
|
2016-12-27 11:02:45 +00:00
|
|
|
path: "{{ kube_cert_dir }}/{{ item }}"
|
2017-03-03 13:21:01 +00:00
|
|
|
register: kubecert_node
|
2016-12-27 11:02:45 +00:00
|
|
|
with_items:
|
|
|
|
- ca.pem
|
2017-08-18 12:46:22 +00:00
|
|
|
- apiserver.pem
|
|
|
|
- apiserver-key.pem
|
|
|
|
- kube-scheduler.pem
|
|
|
|
- kube-scheduler-key.pem
|
|
|
|
- kube-controller-manager.pem
|
|
|
|
- kube-controller-manager-key.pem
|
2018-02-07 08:50:08 +00:00
|
|
|
- front-proxy-client.pem
|
|
|
|
- front-proxy-client-key.pem
|
2017-08-18 12:46:22 +00:00
|
|
|
- admin-{{ inventory_hostname }}.pem
|
|
|
|
- admin-{{ inventory_hostname }}-key.pem
|
|
|
|
- node-{{ inventory_hostname }}.pem
|
2016-12-27 11:02:45 +00:00
|
|
|
- node-{{ inventory_hostname }}-key.pem
|
2017-08-18 12:46:22 +00:00
|
|
|
- kube-proxy-{{ inventory_hostname }}.pem
|
|
|
|
- kube-proxy-{{ inventory_hostname }}-key.pem
|
2016-04-07 15:08:39 +00:00
|
|
|
|
2017-03-03 13:21:01 +00:00
|
|
|
- name: "Check_certs | Set 'gen_certs' to true"
|
|
|
|
set_fact:
|
|
|
|
gen_certs: true
|
|
|
|
when: "not item in kubecert_master.files|map(attribute='path') | list"
|
|
|
|
run_once: true
|
|
|
|
with_items: >-
|
|
|
|
['{{ kube_cert_dir }}/ca.pem',
|
2017-08-18 12:46:22 +00:00
|
|
|
'{{ kube_cert_dir }}/apiserver.pem',
|
|
|
|
'{{ kube_cert_dir }}/apiserver-key.pem',
|
|
|
|
'{{ kube_cert_dir }}/kube-scheduler.pem',
|
|
|
|
'{{ kube_cert_dir }}/kube-scheduler-key.pem',
|
|
|
|
'{{ kube_cert_dir }}/kube-controller-manager.pem',
|
|
|
|
'{{ kube_cert_dir }}/kube-controller-manager-key.pem',
|
2018-02-07 08:50:08 +00:00
|
|
|
'{{ kube_cert_dir }}/front-proxy-client.pem',
|
|
|
|
'{{ kube_cert_dir }}/front-proxy-client-key.pem',
|
2018-04-02 15:57:24 +00:00
|
|
|
'{{ kube_cert_dir }}/service-account-key.pem',
|
2017-08-18 12:46:22 +00:00
|
|
|
{% for host in groups['kube-master'] %}
|
|
|
|
'{{ kube_cert_dir }}/admin-{{ host }}.pem'
|
|
|
|
'{{ kube_cert_dir }}/admin-{{ host }}-key.pem'
|
|
|
|
{% if not loop.last %}{{','}}{% endif %}
|
|
|
|
{% endfor %}]
|
2017-03-03 13:21:01 +00:00
|
|
|
{% for host in groups['k8s-cluster'] %}
|
2017-08-18 12:46:22 +00:00
|
|
|
'{{ kube_cert_dir }}/node-{{ host }}.pem'
|
2017-03-03 13:21:01 +00:00
|
|
|
'{{ kube_cert_dir }}/node-{{ host }}-key.pem'
|
2017-08-18 12:46:22 +00:00
|
|
|
'{{ kube_cert_dir }}/kube-proxy-{{ host }}.pem'
|
|
|
|
'{{ kube_cert_dir }}/kube-proxy-{{ host }}-key.pem'
|
2017-03-03 13:21:01 +00:00
|
|
|
{% if not loop.last %}{{','}}{% endif %}
|
|
|
|
{% endfor %}]
|
|
|
|
|
2017-08-18 12:46:22 +00:00
|
|
|
- name: "Check_certs | Set 'gen_master_certs' to true"
|
|
|
|
set_fact:
|
|
|
|
gen_master_certs: |-
|
|
|
|
{%- set gen = False -%}
|
|
|
|
{% set existing_certs = kubecert_master.files|map(attribute='path')|list|sort %}
|
2018-02-07 08:50:08 +00:00
|
|
|
{% for cert in ['apiserver.pem', 'apiserver-key.pem',
|
|
|
|
'kube-scheduler.pem','kube-scheduler-key.pem',
|
|
|
|
'kube-controller-manager.pem','kube-controller-manager-key.pem',
|
2018-04-02 15:57:24 +00:00
|
|
|
'front-proxy-client.pem','front-proxy-client-key.pem',
|
|
|
|
'service-account-key.pem'] -%}
|
2017-08-18 12:46:22 +00:00
|
|
|
{% set cert_file = "%s/%s.pem"|format(kube_cert_dir, cert) %}
|
|
|
|
{% if not cert_file in existing_certs -%}
|
|
|
|
{%- set gen = True -%}
|
|
|
|
{% endif -%}
|
|
|
|
{% endfor %}
|
|
|
|
{{ gen }}
|
|
|
|
run_once: true
|
|
|
|
|
|
|
|
|
2017-03-03 13:21:01 +00:00
|
|
|
- name: "Check_certs | Set 'gen_node_certs' to true"
|
|
|
|
set_fact:
|
|
|
|
gen_node_certs: |-
|
|
|
|
{
|
|
|
|
{% set existing_certs = kubecert_master.files|map(attribute='path')|list|sort %}
|
|
|
|
{% for host in groups['k8s-cluster'] -%}
|
|
|
|
{% set host_cert = "%s/node-%s-key.pem"|format(kube_cert_dir, host) %}
|
2017-08-18 12:46:22 +00:00
|
|
|
{% set kube_proxy_cert = "%s/kube-proxy-%s-key.pem"|format(kube_cert_dir, host) %}
|
|
|
|
{% if host_cert in existing_certs and kube_proxy_cert in existing_certs -%}
|
2017-03-03 13:21:01 +00:00
|
|
|
"{{ host }}": False,
|
|
|
|
{% else -%}
|
|
|
|
"{{ host }}": True,
|
|
|
|
{% endif -%}
|
|
|
|
{% endfor %}
|
|
|
|
}
|
|
|
|
run_once: true
|
|
|
|
|
2016-04-07 15:08:39 +00:00
|
|
|
- name: "Check_certs | Set 'sync_certs' to true"
|
|
|
|
set_fact:
|
|
|
|
sync_certs: true
|
2017-04-03 14:44:03 +00:00
|
|
|
when: |-
|
2016-04-07 15:08:39 +00:00
|
|
|
{%- set certs = {'sync': False} -%}
|
2017-04-03 14:44:03 +00:00
|
|
|
{% if gen_node_certs[inventory_hostname] or
|
2017-03-03 13:21:01 +00:00
|
|
|
(not kubecert_node.results[0].stat.exists|default(False)) or
|
2018-03-30 14:24:50 +00:00
|
|
|
(not kubecert_node.results[12].stat.exists|default(False)) or
|
|
|
|
(not kubecert_node.results[8].stat.exists|default(False)) or
|
|
|
|
(kubecert_node.results[12].stat.checksum|default('') != kubecert_master.files|selectattr("path", "equalto", kubecert_node.results[12].stat.path)|map(attribute="checksum")|first|default('')) -%}
|
2018-02-05 19:06:55 +00:00
|
|
|
{%- set _ = certs.update({'sync': True}) -%}
|
2017-03-03 13:21:01 +00:00
|
|
|
{% endif %}
|
2016-04-07 15:08:39 +00:00
|
|
|
{{ certs.sync }}
|