feat!: template all ansible dir and rename template to bootstrap (#847)

This commit is contained in:
Devin Buhl authored and GitHub committed 2023-07-12 11:44:23 -04:00
1 parent c7f10b0c6d
commit c9d988a66f
177 files changed
+238 -129

No files matched your search

@@ -0,0 +1,63 @@
---
- name: Set addon facts
ansible.builtin.set_fact:
addon_name: csi-driver-nfs
addon_namespace: kube-system
- name: Ensure directories exist for {{ addon_namespace }}/{{ addon_name }}
when: item.state == 'directory'
ansible.builtin.file:
path: "{{ repository_path }}/kubernetes/apps/{{ addon_namespace }}/{{ addon_name }}/{{ item.path }}"
state: directory
mode: "0755"
with_community.general.filetree: ["../templates/addons/{{ addon_name }}/"]
- name: Template unencrypted files for {{ addon_namespace }}/{{ addon_name }}
when: item.state == 'file' and 'sops' not in item.path
ansible.builtin.template:
src: "{{ item.src }}"
dest: "{{ repository_path }}/kubernetes/apps/{{ addon_namespace }}/{{ addon_name }}/{{ item.path | replace('.j2', '') }}"
mode: "0755"
with_community.general.filetree: ["../templates/addons/{{ addon_name }}/"]
# https://github.com/ansible-collections/community.sops/issues/153
- name: Template encrypted files for {{ addon_namespace }}/{{ addon_name }}
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 encrypted files
when: item.state == 'file' and 'sops' in item.path
community.sops.sops_encrypt:
path: "{{ repository_path }}/kubernetes/apps/{{ addon_namespace }}/{{ addon_name }}/{{ 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/addons/{{ addon_name }}/"]
- 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
+63
View File
@@ -0,0 +1,63 @@
---
- name: Set addon facts
ansible.builtin.set_fact:
addon_name: grafana
addon_namespace: monitoring
- name: Ensure directories exist for {{ addon_namespace }}/{{ addon_name }}
when: item.state == 'directory'
ansible.builtin.file:
path: "{{ repository_path }}/kubernetes/apps/{{ addon_namespace }}/{{ addon_name }}/{{ item.path }}"
state: directory
mode: "0755"
with_community.general.filetree: ["../templates/addons/{{ addon_name }}/"]
- name: Template unencrypted files for {{ addon_namespace }}/{{ addon_name }}
when: item.state == 'file' and 'sops' not in item.path
ansible.builtin.template:
src: "{{ item.src }}"
dest: "{{ repository_path }}/kubernetes/apps/{{ addon_namespace }}/{{ addon_name }}/{{ item.path | replace('.j2', '') }}"
mode: "0755"
with_community.general.filetree: ["../templates/addons/{{ addon_name }}/"]
# https://github.com/ansible-collections/community.sops/issues/153
- name: Template encrypted files for {{ addon_namespace }}/{{ addon_name }}
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 encrypted files
when: item.state == 'file' and 'sops' in item.path
community.sops.sops_encrypt:
path: "{{ repository_path }}/kubernetes/apps/{{ addon_namespace }}/{{ addon_name }}/{{ 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/addons/{{ addon_name }}/"]
- 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
+63
View File
@@ -0,0 +1,63 @@
---
- name: Set addon facts
ansible.builtin.set_fact:
addon_name: hajimari
addon_namespace: default
- name: Ensure directories exist for {{ addon_namespace }}/{{ addon_name }}
when: item.state == 'directory'
ansible.builtin.file:
path: "{{ repository_path }}/kubernetes/apps/{{ addon_namespace }}/{{ addon_name }}/{{ item.path }}"
state: directory
mode: "0755"
with_community.general.filetree: ["../templates/addons/{{ addon_name }}/"]
- name: Template unencrypted files for {{ addon_namespace }}/{{ addon_name }}
when: item.state == 'file' and 'sops' not in item.path
ansible.builtin.template:
src: "{{ item.src }}"
dest: "{{ repository_path }}/kubernetes/apps/{{ addon_namespace }}/{{ addon_name }}/{{ item.path | replace('.j2', '') }}"
mode: "0755"
with_community.general.filetree: ["../templates/addons/{{ addon_name }}/"]
# https://github.com/ansible-collections/community.sops/issues/153
- name: Template encrypted files for {{ addon_namespace }}/{{ addon_name }}
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 encrypted files
when: item.state == 'file' and 'sops' in item.path
community.sops.sops_encrypt:
path: "{{ repository_path }}/kubernetes/apps/{{ addon_namespace }}/{{ addon_name }}/{{ 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/addons/{{ addon_name }}/"]
- 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
@@ -0,0 +1,63 @@
---
- name: Set addon facts
ansible.builtin.set_fact:
addon_name: kube-prometheus-stack
addon_namespace: monitoring
- name: Ensure directories exist for {{ addon_namespace }}/{{ addon_name }}
when: item.state == 'directory'
ansible.builtin.file:
path: "{{ repository_path }}/kubernetes/apps/{{ addon_namespace }}/{{ addon_name }}/{{ item.path }}"
state: directory
mode: "0755"
with_community.general.filetree: ["../templates/addons/{{ addon_name }}/"]
- name: Template unencrypted files for {{ addon_namespace }}/{{ addon_name }}
when: item.state == 'file' and 'sops' not in item.path
ansible.builtin.template:
src: "{{ item.src }}"
dest: "{{ repository_path }}/kubernetes/apps/{{ addon_namespace }}/{{ addon_name }}/{{ item.path | replace('.j2', '') }}"
mode: "0755"
with_community.general.filetree: ["../templates/addons/{{ addon_name }}/"]
# https://github.com/ansible-collections/community.sops/issues/153
- name: Template encrypted files for {{ addon_namespace }}/{{ addon_name }}
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 encrypted files
when: item.state == 'file' and 'sops' in item.path
community.sops.sops_encrypt:
path: "{{ repository_path }}/kubernetes/apps/{{ addon_namespace }}/{{ addon_name }}/{{ 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/addons/{{ addon_name }}/"]
- 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
@@ -0,0 +1,63 @@
---
- name: Set addon facts
ansible.builtin.set_fact:
addon_name: kubernetes-dashboard
addon_namespace: monitoring
- name: Ensure directories exist for {{ addon_namespace }}/{{ addon_name }}
when: item.state == 'directory'
ansible.builtin.file:
path: "{{ repository_path }}/kubernetes/apps/{{ addon_namespace }}/{{ addon_name }}/{{ item.path }}"
state: directory
mode: "0755"
with_community.general.filetree: ["../templates/addons/{{ addon_name }}/"]
- name: Template unencrypted files for {{ addon_namespace }}/{{ addon_name }}
when: item.state == 'file' and 'sops' not in item.path
ansible.builtin.template:
src: "{{ item.src }}"
dest: "{{ repository_path }}/kubernetes/apps/{{ addon_namespace }}/{{ addon_name }}/{{ item.path | replace('.j2', '') }}"
mode: "0755"
with_community.general.filetree: ["../templates/addons/{{ addon_name }}/"]
# https://github.com/ansible-collections/community.sops/issues/153
- name: Template encrypted files for {{ addon_namespace }}/{{ addon_name }}
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 encrypted files
when: item.state == 'file' and 'sops' in item.path
community.sops.sops_encrypt:
path: "{{ repository_path }}/kubernetes/apps/{{ addon_namespace }}/{{ addon_name }}/{{ 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/addons/{{ addon_name }}/"]
- 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
+25
View File
@@ -0,0 +1,25 @@
---
- name: Process addon csi-driver-nfs
when: csi_driver_nfs.enabled | default(false)
ansible.builtin.include_tasks: csi_driver_nfs.yaml
- name: Process addon hajimari
when: hajimari.enabled | default(false)
ansible.builtin.include_tasks: hajimari.yaml
- name: Process addon grafana
when: grafana.enabled | default(false)
ansible.builtin.include_tasks: grafana.yaml
- name: Process addon kubernetes-dashboard
when: kubernetes_dashboard.enabled | default(false)
ansible.builtin.include_tasks: kubernetes_dashboard.yaml
- name: Process addon kube-prometheus-stack
when: kube_prometheus_stack.enabled | default(false)
ansible.builtin.include_tasks: kube_prometheus_stack.yaml
- name: Process addon weave-gitops
when: weave_gitops.enabled | default(false)
ansible.builtin.include_tasks: weave_gitops.yaml
+63
View File
@@ -0,0 +1,63 @@
---
- name: Set addon facts
ansible.builtin.set_fact:
addon_name: weave-gitops
addon_namespace: flux-system
- name: Ensure directories exist for {{ addon_namespace }}/{{ addon_name }}
when: item.state == 'directory'
ansible.builtin.file:
path: "{{ repository_path }}/kubernetes/apps/{{ addon_namespace }}/{{ addon_name }}/{{ item.path }}"
state: directory
mode: "0755"
with_community.general.filetree: ["../templates/addons/{{ addon_name }}/"]
- name: Template unencrypted files for {{ addon_namespace }}/{{ addon_name }}
when: item.state == 'file' and 'sops' not in item.path
ansible.builtin.template:
src: "{{ item.src }}"
dest: "{{ repository_path }}/kubernetes/apps/{{ addon_namespace }}/{{ addon_name }}/{{ item.path | replace('.j2', '') }}"
mode: "0755"
with_community.general.filetree: ["../templates/addons/{{ addon_name }}/"]
# https://github.com/ansible-collections/community.sops/issues/153
- name: Template encrypted files for {{ addon_namespace }}/{{ addon_name }}
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 encrypted files
when: item.state == 'file' and 'sops' in item.path
community.sops.sops_encrypt:
path: "{{ repository_path }}/kubernetes/apps/{{ addon_namespace }}/{{ addon_name }}/{{ 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/addons/{{ addon_name }}/"]
- 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
+121
View File
@@ -0,0 +1,121 @@
---
- name: Ensure Kubernetes directories exist
when: item.state == 'directory'
ansible.builtin.file:
path: "{{ repository_path }}/ansible/{{ item.path }}"
state: directory
mode: "0755"
with_community.general.filetree: ["../templates/ansible/"]
- name: Template Ansible unencrypted files
when: item.state == 'file' and 'sops' not in item.path and '.DS_Store' not in item.path
ansible.builtin.template:
src: "{{ item.src }}"
dest: "{{ repository_path }}/ansible/{{ item.path | regex_replace('.j2$', '') }}"
mode: "0755"
with_community.general.filetree: ["../templates/ansible/"]
# https://github.com/ansible-collections/community.sops/issues/153
- name: Template Ansible 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 Ansible encrypted files
when: item.state == 'file' and 'sops' in item.path
community.sops.sops_encrypt:
path: "{{ repository_path }}/ansible/{{ 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/ansible/"]
- name: Template encrypted node secrets
community.sops.sops_encrypt:
path: "{{ repository_path }}/ansible/inventory/host_vars/{{ item.name }}.sops.yaml"
age: ["{{ bootstrap_age_public_key }}"]
content_yaml: "{{ lookup('ansible.builtin.template', 'templates/node.sops.yaml.j2', template_vars=dict(password=item.password)) | from_yaml }}"
mode: "0755"
force: true
loop: "{{ bootstrap_nodes.master + bootstrap_nodes.worker | default([]) }}"
loop_control:
label: "{{ item.address }}"
- 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
# - name: Template Ansible configuration
# ansible.builtin.template:
# src: "{{ item.src }}"
# dest: "{{ repository_path }}/{{ item.dest }}"
# mode: "0755"
# loop:
# - src: templates/ansible/supplemental.yaml.j2
# dest: ./ansible/inventory/group_vars/kubernetes/supplemental.yaml
# - src: templates/ansible/hosts.yaml.j2
# dest: ./ansible/inventory/hosts.yaml
# # https://github.com/ansible-collections/community.sops/issues/153
# - name: Template Ansible 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 encrypted node secrets
# community.sops.sops_encrypt:
# path: "{{ repository_path }}/ansible/inventory/host_vars/{{ item.name }}.sops.yaml"
# age: ["{{ bootstrap_age_public_key }}"]
# content_yaml: "{{ lookup('ansible.builtin.template', 'templates/ansible/node.sops.yaml.j2', template_vars=dict(password=item.password)) | from_yaml }}"
# mode: "0755"
# force: true
# loop: "{{ bootstrap_nodes.master + bootstrap_nodes.worker | default([]) }}"
# loop_control:
# label: "{{ item.address }}"
# - 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
+58
View File
@@ -0,0 +1,58 @@
---
- name: Ensure Kubernetes directories exist
when: item.state == 'directory'
ansible.builtin.file:
path: "{{ repository_path }}/kubernetes/{{ item.path }}"
state: directory
mode: "0755"
with_community.general.filetree: ["../templates/kubernetes/"]
- name: Template Kubernetes unencrypted files
when: item.state == 'file' and 'sops' not in item.path and '.DS_Store' not in item.path
ansible.builtin.template:
src: "{{ item.src }}"
dest: "{{ repository_path }}/kubernetes/{{ item.path | regex_replace('.j2$', '') }}"
mode: "0755"
with_community.general.filetree: ["../templates/kubernetes/"]
# https://github.com/ansible-collections/community.sops/issues/153
- 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
+6
View File
@@ -0,0 +1,6 @@
---
- name: Template Sops configuration file
ansible.builtin.template:
src: "templates/.sops.yaml.j2"
dest: "{{ repository_path }}/.sops.yaml"
mode: "0755"
+22
View File
@@ -0,0 +1,22 @@
---
- name: Query age key file
ansible.builtin.stat:
path: ~/.config/sops/age/keys.txt
register: result
- name: Check if age key file exists
ansible.builtin.assert:
that: [result.stat.exists]
success_msg: Age file ~/.config/sops/age/keys.txt exists
fail_msg: Age file ~/.config/sops/age/keys.txt does not exist
- name: Query age key file contents
ansible.builtin.set_fact:
age_contents: "{{ lookup('file', '~/.config/sops/age/keys.txt') }}"
- name: Check if age public keys match
ansible.builtin.assert:
that:
- "'{{ bootstrap_age_public_key }}' in age_contents"
success_msg: Age public key {{ bootstrap_age_public_key }} exists
fail_msg: Age public key {{ bootstrap_age_public_key }} does not exist
+9
View File
@@ -0,0 +1,9 @@
---
- name: Check for required CLI tools
ansible.builtin.shell: |
command -v {{ item }} >/dev/null 2>&1
loop: [age, cloudflared, flux, git, pip3, sops, task]
changed_when: false
check_mode: false
register: result
failed_when: result.rc != 0 and result.rc != 127
@@ -0,0 +1,34 @@
---
- name: Query Cloudflare zone
ansible.builtin.uri:
url: "https://api.cloudflare.com/client/v4/zones?name={{ bootstrap_cloudflare_domain }}&status=active"
headers:
Authorization: "Bearer {{ bootstrap_cloudflare_token }}"
Content-Type: application/json
timeout: 5
return_content: true
body_format: json
register: result
- name: Check if Cloudflare zone exists
ansible.builtin.assert:
that: ["result.json.success == true"]
success_msg: "Cloudflare zone {{ bootstrap_cloudflare_domain }} exists"
fail_msg: "Cloudflare zone {{ bootstrap_cloudflare_domain }} does not exist"
- name: Query Cloudflared tunnel
ansible.builtin.uri:
url: "https://api.cloudflare.com/client/v4/accounts/{{ bootstrap_cloudflare_account_tag }}/cfd_tunnel/{{ bootstrap_cloudflare_tunnel_id }}"
headers:
Authorization: "Bearer {{ bootstrap_cloudflare_token }}"
Content-Type: application/json
timeout: 5
return_content: true
body_format: json
register: result
- name: Check if Cloudflared tunnel exists
ansible.builtin.assert:
that: ["result.json.success == true"]
success_msg: "Cloudflared tunnel {{ bootstrap_cloudflare_tunnel_id }} exists"
fail_msg: "Cloudflared tunnel {{ bootstrap_cloudflare_tunnel_id }} does not exist"
+30
View File
@@ -0,0 +1,30 @@
---
- name: Query Github username
ansible.builtin.uri:
url: "https://api.github.com/users/{{ bootstrap_github_username }}"
timeout: 5
return_content: true
body_format: json
register: result
- name: Check if username exists
ansible.builtin.assert:
that:
- "result.json.login == '{{ bootstrap_github_username }}'"
success_msg: "Github user {{ bootstrap_github_username }} exists"
fail_msg: "Github user {{ bootstrap_github_username }} does not exist"
- name: Query Github repo
ansible.builtin.uri:
url: "https://api.github.com/repos/{{ bootstrap_github_username }}/{{ bootstrap_github_repository_name }}"
timeout: 5
return_content: true
body_format: json
register: result
- name: Check if repo exists
ansible.builtin.assert:
that:
- "result.json.full_name == '{{ bootstrap_github_username }}/{{ bootstrap_github_repository_name }}'"
success_msg: "Github repo {{ bootstrap_github_username }}/{{ bootstrap_github_repository_name }} exists"
fail_msg: "Github repo {{ bootstrap_github_username }}/{{ bootstrap_github_repository_name }} does not exist"
+6
View File
@@ -0,0 +1,6 @@
---
- name: Verify configuration
ansible.builtin.include_tasks: "{{ task }}.yaml"
loop: [vars, age, cli, net, cloudflare, github]
loop_control:
loop_var: task
+94
View File
@@ -0,0 +1,94 @@
---
- name: Verify master node count
ansible.builtin.assert:
that:
- "{{ bootstrap_nodes.master | length > 0 }}"
- "{{ bootstrap_nodes.master | length is odd }}"
success_msg: "Master node count {{ bootstrap_nodes.master | length }} is correct."
fail_msg: "Master node count {{ bootstrap_nodes.master | length }} is not greater than 0 or is not odd."
- name: Verify node CIDR
ansible.builtin.assert:
that: ["{{ bootstrap_node_cidr is ansible.utils.ipv4 }}"]
success_msg: "Node CIDR {{ bootstrap_node_cidr }} is valid."
fail_msg: "Node CIDR {{ bootstrap_node_cidr }} is invalid."
- name: Verify cluster CIDR
ansible.builtin.assert:
that: ["{{ bootstrap_cluster_cidr is ansible.utils.ipv4 }}"]
success_msg: "Cluster CIDR {{ bootstrap_cluster_cidr }} is valid."
fail_msg: "Cluster CIDR {{ bootstrap_cluster_cidr }} is invalid."
- name: Verify service CIDR
ansible.builtin.assert:
that: ["{{ bootstrap_service_cidr is ansible.utils.ipv4 }}"]
success_msg: "Service CIDR {{ bootstrap_service_cidr }} is valid."
fail_msg: "Service CIDR {{ bootstrap_service_cidr }} is invalid."
- name: Verify k8s_gateway
ansible.builtin.assert:
that: ["{{ bootstrap_k8s_gateway_addr is ansible.utils.ipv4 }}"]
success_msg: "k8s_gateway address {{ bootstrap_k8s_gateway_addr }} is valid."
fail_msg: "k8s_gateway address {{ bootstrap_k8s_gateway_addr }} is invalid."
- name: Verify k8s_gateway in node CIDR
ansible.builtin.assert:
that: ["{{ bootstrap_node_cidr | ansible.utils.network_in_usable(bootstrap_k8s_gateway_addr) }}"]
success_msg: "k8s_gateway address {{ bootstrap_k8s_gateway_addr }} is within {{ bootstrap_node_cidr }}."
fail_msg: "k8s_gateway address {{ bootstrap_k8s_gateway_addr }} is not within {{ bootstrap_node_cidr }}."
- name: Verify ingress-nginx
ansible.builtin.assert:
that: ["{{ bootstrap_ingress_nginx_addr is ansible.utils.ipv4 }}"]
success_msg: "ingress-nginx address {{ bootstrap_ingress_nginx_addr }} is valid."
fail_msg: "ingress-nginx address {{ bootstrap_ingress_nginx_addr }} is invalid."
- name: Verify ingress-nginx in node CIDR
ansible.builtin.assert:
that: ["{{ bootstrap_node_cidr | ansible.utils.network_in_usable(bootstrap_ingress_nginx_addr) }}"]
success_msg: "ingress-nginx address {{ bootstrap_ingress_nginx_addr }} is within {{ bootstrap_node_cidr }}."
fail_msg: "ingress-nginx address {{ bootstrap_ingress_nginx_addr }} is not within {{ bootstrap_node_cidr }}."
- name: Verify kube-vip
ansible.builtin.assert:
that: ["{{ bootstrap_kube_vip_addr is ansible.utils.ipv4 }}"]
success_msg: "kube-vip address {{ bootstrap_kube_vip_addr }} is valid."
fail_msg: "kube-vip address {{ bootstrap_kube_vip_addr }} is invalid."
- name: Verify kube-vip in node CIDR
ansible.builtin.assert:
that: ["{{ bootstrap_node_cidr | ansible.utils.network_in_usable(bootstrap_kube_vip_addr) }}"]
success_msg: "kube-vip address {{ bootstrap_kube_vip_addr }} is within {{ bootstrap_node_cidr }}."
fail_msg: "kube-vip address {{ bootstrap_kube_vip_addr }} is not within {{ bootstrap_node_cidr }}."
- name: Verify nodes are not the same IPs as k8s_gateway, ingress-nginx or kube-vip
ansible.builtin.assert:
that:
- "{{ item.address not in (bootstrap_k8s_gateway_addr, bootstrap_ingress_nginx_addr, bootstrap_kube_vip_addr) }}"
success_msg: "Node address {{ item.address }} is different than k8s_gateway, ingress-nginx or kube-vip."
fail_msg: "Node address {{ item.address }} is not different than k8s_gateway, ingress-nginx or kube-vip."
quiet: true
loop: "{{ bootstrap_nodes.master + bootstrap_nodes.worker | default([]) }}"
loop_control:
label: "{{ item.address }}"
- name: Verify nodes are in node CIDR
ansible.builtin.assert:
that: ["{{ bootstrap_node_cidr | ansible.utils.network_in_usable(item.address) }}"]
success_msg: "Node address {{ item.address }} is within {{ bootstrap_node_cidr }}."
fail_msg: "Node address {{ item.address }} is not within {{ bootstrap_node_cidr }}."
quiet: true
loop: "{{ bootstrap_nodes.master + bootstrap_nodes.worker | default([]) }}"
loop_control:
label: "{{ item.address }}"
- name: Verify SSH port is reachable
ansible.builtin.wait_for:
host: "{{ item.address }}"
port: 22
search_regex: OpenSSH
timeout: 10
connection: local
loop: "{{ bootstrap_nodes.master + bootstrap_nodes.worker | default([]) }}"
loop_control:
label: "{{ item.address }}"
+36
View File
@@ -0,0 +1,36 @@
---
- name: Verify required bootstrap vars are set
ansible.builtin.assert:
that:
- "{{ item }} | default('', true) | trim != ''"
success_msg: "Required bootstrap var {{ item }} exists and is defined"
fail_msg: "Required bootstrap var {{ item }} does not exists or is not defined"
loop:
- bootstrap_github_username
- bootstrap_github_repository_name
- bootstrap_age_public_key
- bootstrap_timezone
- bootstrap_acme_email
- bootstrap_flux_github_webhook_token
- bootstrap_cloudflare_domain
- bootstrap_cloudflare_token
- bootstrap_cloudflare_account_tag
- bootstrap_cloudflare_tunnel_secret
- bootstrap_cloudflare_tunnel_id
- bootstrap_node_cidr
- bootstrap_k8s_gateway_addr
- bootstrap_ingress_nginx_addr
- bootstrap_kube_vip_addr
- bootstrap_cluster_cidr
- bootstrap_service_cidr
- name: Verify bootstrap node names are valid
ansible.builtin.assert:
that:
- "item.name is match('^[a-z0-9-]+$')"
success_msg: "Node name {{ item.name }} is valid"
fail_msg: "Node name {{ item.name }} is not valid"
loop: "{{ bootstrap_nodes.master + bootstrap_nodes.worker | default([]) }}"
loop_control:
label: "{{ item.name }}"