2017-02-09 05:41:36 +08:00
|
|
|
---
|
2017-04-12 18:37:50 +08:00
|
|
|
- include: sync_kube_master_certs.yml
|
|
|
|
when: inventory_hostname in groups['kube-master']
|
|
|
|
tags: k8s-secrets
|
|
|
|
|
|
|
|
- include: sync_kube_node_certs.yml
|
|
|
|
when: inventory_hostname in groups['k8s-cluster']
|
|
|
|
tags: k8s-secrets
|
2017-02-09 05:41:36 +08:00
|
|
|
|
|
|
|
- name: gen_certs_vault | Read in the local credentials
|
|
|
|
command: cat /etc/vault/roles/kube/userpass
|
|
|
|
register: kube_vault_creds_cat
|
2017-08-20 18:53:58 +08:00
|
|
|
delegate_to: "{{ groups['k8s-cluster'][0] }}"
|
2017-02-09 05:41:36 +08:00
|
|
|
|
|
|
|
- name: gen_certs_vault | Set facts for read Vault Creds
|
|
|
|
set_fact:
|
2017-08-20 18:53:58 +08:00
|
|
|
kube_vault_creds: "{{ kube_vault_creds_cat.stdout|from_json }}"
|
|
|
|
delegate_to: "{{ groups['k8s-cluster'][0] }}"
|
2017-02-09 05:41:36 +08:00
|
|
|
|
|
|
|
- name: gen_certs_vault | Log into Vault and obtain an token
|
|
|
|
uri:
|
2017-08-20 18:53:58 +08:00
|
|
|
url: "{{ hostvars[groups['vault'][0]]['vault_leader_url'] }}/v1/auth/userpass/login/{{ kube_vault_creds.username }}"
|
2017-02-09 05:41:36 +08:00
|
|
|
headers:
|
|
|
|
Accept: application/json
|
2017-04-12 18:37:50 +08:00
|
|
|
Content-Type: application/json
|
2017-02-09 05:41:36 +08:00
|
|
|
method: POST
|
|
|
|
body_format: json
|
|
|
|
body:
|
|
|
|
password: "{{ kube_vault_creds.password }}"
|
|
|
|
register: kube_vault_login_result
|
2017-08-20 18:53:58 +08:00
|
|
|
delegate_to: "{{ groups['k8s-cluster'][0] }}"
|
2017-02-09 05:41:36 +08:00
|
|
|
|
|
|
|
- name: gen_certs_vault | Set fact for Vault API token
|
|
|
|
set_fact:
|
|
|
|
kube_vault_headers:
|
2017-08-24 17:09:52 +08:00
|
|
|
Accept: application/json
|
|
|
|
Content-Type: application/json
|
|
|
|
X-Vault-Token: "{{ kube_vault_login_result.get('json',{}).get('auth', {}).get('client_token') }}"
|
2017-08-20 18:53:58 +08:00
|
|
|
run_once: true
|
2017-02-09 05:41:36 +08:00
|
|
|
|
|
|
|
# Issue certs to kube-master nodes
|
|
|
|
- include: ../../../vault/tasks/shared/issue_cert.yml
|
|
|
|
vars:
|
|
|
|
issue_cert_copy_ca: "{{ item == kube_master_certs_needed|first }}"
|
|
|
|
issue_cert_file_group: "{{ kube_cert_group }}"
|
|
|
|
issue_cert_file_owner: kube
|
|
|
|
issue_cert_headers: "{{ kube_vault_headers }}"
|
|
|
|
issue_cert_hosts: "{{ groups['kube-master'] }}"
|
|
|
|
issue_cert_path: "{{ item }}"
|
|
|
|
issue_cert_role: kube
|
|
|
|
issue_cert_url: "{{ hostvars[groups.vault|first]['vault_leader_url'] }}"
|
2017-08-30 21:03:22 +08:00
|
|
|
issue_cert_mount_path: "{{ kube_vault_mount_path }}"
|
2017-02-09 05:41:36 +08:00
|
|
|
with_items: "{{ kube_master_certs_needed|d([]) }}"
|
|
|
|
when: inventory_hostname in groups['kube-master']
|
|
|
|
|
2017-08-30 21:03:22 +08:00
|
|
|
- name: gen_certs_vault | Set fact about certificate alt names
|
|
|
|
set_fact:
|
|
|
|
kube_cert_alt_names: >-
|
|
|
|
{{
|
|
|
|
groups['kube-master'] +
|
|
|
|
['kubernetes.default.svc.cluster.local', 'kubernetes.default.svc', 'kubernetes.default', 'kubernetes'] +
|
|
|
|
['localhost']
|
|
|
|
}}
|
|
|
|
run_once: true
|
|
|
|
|
|
|
|
- name: gen_certs_vault | Add external load balancer domain name to certificate alt names
|
|
|
|
set_fact:
|
|
|
|
kube_cert_alt_names: "{{ kube_cert_alt_names + [apiserver_loadbalancer_domain_name] }}"
|
|
|
|
when: loadbalancer_apiserver is defined and apiserver_loadbalancer_domain_name is defined
|
|
|
|
run_once: true
|
|
|
|
|
2017-02-09 05:41:36 +08:00
|
|
|
- include: ../../../vault/tasks/shared/issue_cert.yml
|
|
|
|
vars:
|
2017-08-30 21:03:22 +08:00
|
|
|
issue_cert_alt_names: "{{ kube_cert_alt_names }}"
|
2017-02-09 05:41:36 +08:00
|
|
|
issue_cert_file_group: "{{ kube_cert_group }}"
|
|
|
|
issue_cert_file_owner: kube
|
2017-04-12 18:37:50 +08:00
|
|
|
issue_cert_headers: "{{ kube_vault_headers }}"
|
2017-02-09 05:41:36 +08:00
|
|
|
issue_cert_hosts: "{{ groups['kube-master'] }}"
|
|
|
|
issue_cert_ip_sans: >-
|
|
|
|
[
|
|
|
|
{%- for host in groups['kube-master'] -%}
|
|
|
|
"{{ hostvars[host]['ansible_default_ipv4']['address'] }}",
|
2017-08-20 18:53:58 +08:00
|
|
|
{%- if hostvars[host]['ip'] is defined -%}
|
|
|
|
"{{ hostvars[host]['ip'] }}",
|
|
|
|
{%- endif -%}
|
2017-02-09 05:41:36 +08:00
|
|
|
{%- endfor -%}
|
|
|
|
"127.0.0.1","::1","{{ kube_apiserver_ip }}"
|
|
|
|
]
|
|
|
|
issue_cert_path: "{{ item }}"
|
|
|
|
issue_cert_role: kube
|
|
|
|
issue_cert_url: "{{ hostvars[groups.vault|first]['vault_leader_url'] }}"
|
2017-08-30 21:03:22 +08:00
|
|
|
issue_cert_mount_path: "{{ kube_vault_mount_path }}"
|
2017-08-20 18:53:58 +08:00
|
|
|
with_items: "{{ kube_master_components_certs_needed|d([]) }}"
|
2017-02-09 05:41:36 +08:00
|
|
|
when: inventory_hostname in groups['kube-master']
|
2017-08-30 21:03:22 +08:00
|
|
|
notify: set secret_changed
|
2017-02-09 05:41:36 +08:00
|
|
|
|
|
|
|
# Issue node certs to k8s-cluster nodes
|
|
|
|
- include: ../../../vault/tasks/shared/issue_cert.yml
|
|
|
|
vars:
|
|
|
|
issue_cert_copy_ca: "{{ item == kube_node_certs_needed|first }}"
|
|
|
|
issue_cert_file_group: "{{ kube_cert_group }}"
|
|
|
|
issue_cert_file_owner: kube
|
2017-04-12 18:37:50 +08:00
|
|
|
issue_cert_headers: "{{ kube_vault_headers }}"
|
2017-02-09 05:41:36 +08:00
|
|
|
issue_cert_hosts: "{{ groups['k8s-cluster'] }}"
|
|
|
|
issue_cert_path: "{{ item }}"
|
|
|
|
issue_cert_role: kube
|
|
|
|
issue_cert_url: "{{ hostvars[groups.vault|first]['vault_leader_url'] }}"
|
2017-08-30 21:03:22 +08:00
|
|
|
issue_cert_mount_path: "{{ kube_vault_mount_path }}"
|
2017-02-09 05:41:36 +08:00
|
|
|
with_items: "{{ kube_node_certs_needed|d([]) }}"
|
|
|
|
when: inventory_hostname in groups['k8s-cluster']
|
2017-08-20 18:53:58 +08:00
|
|
|
|
|
|
|
- include: ../../../vault/tasks/shared/issue_cert.yml
|
|
|
|
vars:
|
|
|
|
issue_cert_copy_ca: "{{ item == kube_proxy_certs_needed|first }}"
|
|
|
|
issue_cert_file_group: "{{ kube_cert_group }}"
|
|
|
|
issue_cert_file_owner: kube
|
|
|
|
issue_cert_headers: "{{ kube_vault_headers }}"
|
|
|
|
issue_cert_hosts: "{{ groups['k8s-cluster'] }}"
|
|
|
|
issue_cert_path: "{{ item }}"
|
|
|
|
issue_cert_role: kube
|
|
|
|
issue_cert_url: "{{ hostvars[groups.vault|first]['vault_leader_url'] }}"
|
2017-08-30 21:03:22 +08:00
|
|
|
issue_cert_mount_path: "{{ kube_vault_mount_path }}"
|
2017-08-20 18:53:58 +08:00
|
|
|
with_items: "{{ kube_proxy_certs_needed|d([]) }}"
|
|
|
|
when: inventory_hostname in groups['k8s-cluster']
|