2018-03-15 19:20:05 +00:00
|
|
|
---
|
2019-02-19 15:31:45 +00:00
|
|
|
- name: Check if secret for encrypting data at rest already exist
|
|
|
|
stat:
|
|
|
|
path: "{{ kube_cert_dir }}/secrets_encryption.yaml"
|
2021-02-10 13:36:59 +00:00
|
|
|
get_attributes: no
|
|
|
|
get_checksum: no
|
|
|
|
get_mime: no
|
2019-02-19 15:31:45 +00:00
|
|
|
register: secrets_encryption_file
|
|
|
|
|
|
|
|
- name: Slurp secrets_encryption file if it exists
|
|
|
|
slurp:
|
|
|
|
src: "{{ kube_cert_dir }}/secrets_encryption.yaml"
|
|
|
|
register: secret_file_encoded
|
|
|
|
when: secrets_encryption_file.stat.exists
|
|
|
|
|
|
|
|
- name: Base 64 Decode slurped secrets_encryption.yaml file
|
|
|
|
set_fact:
|
2019-05-02 21:24:21 +00:00
|
|
|
secret_file_decoded: "{{ secret_file_encoded['content'] | b64decode | from_yaml }}"
|
2019-02-19 15:31:45 +00:00
|
|
|
when: secrets_encryption_file.stat.exists
|
|
|
|
|
|
|
|
- name: Extract secret value from secrets_encryption.yaml
|
|
|
|
set_fact:
|
2019-05-02 21:24:21 +00:00
|
|
|
kube_encrypt_token_extracted: "{{ secret_file_decoded | json_query(secrets_encryption_query) | first | b64decode }}"
|
2019-02-19 15:31:45 +00:00
|
|
|
when: secrets_encryption_file.stat.exists
|
|
|
|
|
|
|
|
- name: Set kube_encrypt_token across master nodes
|
|
|
|
set_fact:
|
|
|
|
kube_encrypt_token: "{{ kube_encrypt_token_extracted }}"
|
|
|
|
delegate_to: "{{ item }}"
|
|
|
|
delegate_facts: true
|
2021-03-24 00:26:05 +00:00
|
|
|
with_inventory_hostnames: kube_control_plane
|
2019-02-19 15:31:45 +00:00
|
|
|
when: kube_encrypt_token_extracted is defined
|
|
|
|
|
2018-03-15 19:20:05 +00:00
|
|
|
- name: Write secrets for encrypting secret data at rest
|
|
|
|
template:
|
|
|
|
src: secrets_encryption.yaml.j2
|
2018-12-07 07:11:53 +00:00
|
|
|
dest: "{{ kube_cert_dir }}/secrets_encryption.yaml"
|
2018-03-15 19:20:05 +00:00
|
|
|
owner: root
|
|
|
|
group: "{{ kube_cert_group }}"
|
|
|
|
mode: 0640
|
|
|
|
tags:
|
|
|
|
- kube-apiserver
|