feat(ansible): Add addon support (#836)

This commit is contained in:
Devin Buhl authored and GitHub committed 2023-07-06 14:21:32 -04:00
1 parent 8af4377aa3
commit 34527bd3e2
41 files changed
+502 -118

No files matched your search

+47 -47
View File
@@ -1,58 +1,58 @@
---
- name: Get absolute path to this Git repository # noqa: command-instead-of-module
ansible.builtin.command: git rev-parse --show-toplevel
changed_when: false
check_mode: false
register: repository_path
failed_when: repository_path.rc != 0
- name: Ensure Kubernetes directories exist
when: item.state == 'directory'
ansible.builtin.file:
path: "{{ repository_path.stdout }}/kubernetes/{{ item.path }}"
path: "{{ repository_path }}/kubernetes/{{ item.path }}"
state: directory
mode: "0755"
with_community.general.filetree:
- ../templates/kubernetes/
when: item.state == 'directory'
with_community.general.filetree: ["../templates/kubernetes/"]
- name: Template Kubernetes unencrypted files
when: item.state == 'file' and 'sops' not in item.path
ansible.builtin.template:
src: "{{ item.src }}"
dest: "{{ repository_path.stdout }}/kubernetes/{{ item.path | replace('.j2', '') }}"
with_community.general.filetree:
- ../templates/kubernetes/
when: item.state == 'file' and 'sops' not in item.path
dest: "{{ repository_path }}/kubernetes/{{ item.path | replace('.j2', '') }}"
mode: "0755"
with_community.general.filetree: ["../templates/kubernetes/"]
# https://github.com/ansible-collections/community.sops/issues/153
- name: Backup sops configuration file
ansible.builtin.copy:
src: "{{ repository_path.stdout }}/.sops.yaml"
dest: "{{ repository_path.stdout }}/.sops.yaml.orig"
mode: "0755"
- name: Remove sops configuration file
ansible.builtin.file:
path: "{{ repository_path.stdout }}/.sops.yaml"
state: absent
- name: Template Kubernetes unencrypted files
community.sops.sops_encrypt:
path: "{{ repository_path.stdout }}/kubernetes/{{ item.path | replace('.j2', '') }}"
encrypted_regex: ^(data|stringData)$
age: ["{{ bootstrap_age_public_key }}"]
content_yaml: "{{ lookup('ansible.builtin.template', item.src) | from_yaml }}"
mode: "0755"
force: true
with_community.general.filetree:
- ../templates/kubernetes/
when: item.state == 'file' and 'sops' in item.path
# https://github.com/ansible-collections/community.sops/issues/153
- name: Restore sops configuration file
ansible.builtin.copy:
src: "{{ repository_path.stdout }}/.sops.yaml.orig"
dest: "{{ repository_path.stdout }}/.sops.yaml"
mode: "0755"
- name: Remove backup sops configuration file
ansible.builtin.file:
path: "{{ repository_path.stdout }}/.sops.yaml.orig"
state: absent
- name: Template Kubernetes encrypted files
block:
- name: Rename Sops configuration file
ansible.builtin.copy:
src: "{{ repository_path }}/.sops.yaml"
dest: "{{ repository_path }}/.sops.yaml.orig"
mode: "0755"
- name: Remove Sops configuration file
ansible.builtin.file:
path: "{{ repository_path }}/.sops.yaml"
state: absent
- name: Template Kubernetes encrypted files
when: item.state == 'file' and 'sops' in item.path
community.sops.sops_encrypt:
path: "{{ repository_path }}/kubernetes/{{ item.path | replace('.j2', '') }}"
encrypted_regex: ^(data|stringData)$
age: ["{{ bootstrap_age_public_key }}"]
content_yaml: "{{ lookup('ansible.builtin.template', item.src) | from_yaml }}"
mode: "0755"
force: true
with_community.general.filetree: ["../templates/kubernetes/"]
- name: Restore Sops configuration file
ansible.builtin.copy:
src: "{{ repository_path }}/.sops.yaml.orig"
dest: "{{ repository_path }}/.sops.yaml"
mode: "0755"
- name: Remove backed up Sops configuration file
ansible.builtin.file:
path: "{{ repository_path }}/.sops.yaml.orig"
state: absent
rescue:
- name: Restore Sops configuration file
ansible.builtin.copy:
src: "{{ repository_path }}/.sops.yaml.orig"
dest: "{{ repository_path }}/.sops.yaml"
mode: "0755"
- name: Remove backed up Sops configuration file
ansible.builtin.file:
path: "{{ repository_path }}/.sops.yaml.orig"
state: absent