From c8ebab75087d60c20438c75467dc2bca628d0cd0 Mon Sep 17 00:00:00 2001 From: Devin Buhl Date: Thu, 11 Jan 2024 16:46:36 -0500 Subject: [PATCH] feat: do not template out k3s ansible when k0s is choosen Signed-off-by: Devin Buhl --- .taskfiles/K0sTasks.yaml | 6 ++++- bootstrap/configure.yaml | 1 + bootstrap/tasks/ansible/main.yaml | 24 +++++++++++++------ bootstrap/tasks/k0s/main.yaml | 2 +- bootstrap/tasks/kubernetes/main.yaml | 14 ++++++----- .../{inventory/host_vars => k0s}/.gitkeep.j2 | 0 .../group_vars/kubernetes/main.yaml.j2 | 0 .../inventory/group_vars/master/main.yaml.j2 | 0 .../inventory/group_vars/worker/main.yaml.j2 | 0 .../playbooks/cluster-installation.yaml.j2 | 0 .../playbooks/cluster-kube-vip.yaml.j2 | 0 .../{ => k3s}/playbooks/tasks/cilium.yaml.j2 | 0 .../{ => k3s}/playbooks/tasks/coredns.yaml.j2 | 0 .../{ => k3s}/playbooks/tasks/cruft.yaml.j2 | 0 .../playbooks/tasks/kubeconfig.yaml.j2 | 0 .../custom-cilium-helmchart.yaml.j2.j2 | 0 .../templates/custom-cilium-l2.yaml.j2.j2 | 0 .../custom-coredns-helmchart.yaml.j2.j2 | 0 .../templates/kube-vip-static-pod.yaml.j2.j2 | 0 .../ansible/{ => shared}/.ansible-lint.j2 | 0 .../kubernetes/supplemental.yaml.j2 | 0 .../shared/inventory/host_vars/.gitkeep.j2 | 0 .../{ => shared}/inventory/hosts.yaml.j2 | 0 .../playbooks/cluster-nuke.yaml.j2 | 0 .../playbooks/cluster-prepare.yaml.j2 | 0 .../playbooks/cluster-reboot.yaml.j2 | 0 .../playbooks/cluster-rollout-update.yaml.j2 | 0 .../templates/{ => k0s}/k0s-config.yaml.j2 | 0 bootstrap/vars/.gitignore | 1 + 29 files changed, 33 insertions(+), 15 deletions(-) rename bootstrap/templates/ansible/{inventory/host_vars => k0s}/.gitkeep.j2 (100%) rename bootstrap/templates/ansible/{ => k3s}/inventory/group_vars/kubernetes/main.yaml.j2 (100%) rename bootstrap/templates/ansible/{ => k3s}/inventory/group_vars/master/main.yaml.j2 (100%) rename bootstrap/templates/ansible/{ => k3s}/inventory/group_vars/worker/main.yaml.j2 (100%) rename bootstrap/templates/ansible/{ => k3s}/playbooks/cluster-installation.yaml.j2 (100%) rename bootstrap/templates/ansible/{ => k3s}/playbooks/cluster-kube-vip.yaml.j2 (100%) rename bootstrap/templates/ansible/{ => k3s}/playbooks/tasks/cilium.yaml.j2 (100%) rename bootstrap/templates/ansible/{ => k3s}/playbooks/tasks/coredns.yaml.j2 (100%) rename bootstrap/templates/ansible/{ => k3s}/playbooks/tasks/cruft.yaml.j2 (100%) rename bootstrap/templates/ansible/{ => k3s}/playbooks/tasks/kubeconfig.yaml.j2 (100%) rename bootstrap/templates/ansible/{ => k3s}/playbooks/templates/custom-cilium-helmchart.yaml.j2.j2 (100%) rename bootstrap/templates/ansible/{ => k3s}/playbooks/templates/custom-cilium-l2.yaml.j2.j2 (100%) rename bootstrap/templates/ansible/{ => k3s}/playbooks/templates/custom-coredns-helmchart.yaml.j2.j2 (100%) rename bootstrap/templates/ansible/{ => k3s}/playbooks/templates/kube-vip-static-pod.yaml.j2.j2 (100%) rename bootstrap/templates/ansible/{ => shared}/.ansible-lint.j2 (100%) rename bootstrap/templates/ansible/{ => shared}/inventory/group_vars/kubernetes/supplemental.yaml.j2 (100%) create mode 100644 bootstrap/templates/ansible/shared/inventory/host_vars/.gitkeep.j2 rename bootstrap/templates/ansible/{ => shared}/inventory/hosts.yaml.j2 (100%) rename bootstrap/templates/ansible/{ => shared}/playbooks/cluster-nuke.yaml.j2 (100%) rename bootstrap/templates/ansible/{ => shared}/playbooks/cluster-prepare.yaml.j2 (100%) rename bootstrap/templates/ansible/{ => shared}/playbooks/cluster-reboot.yaml.j2 (100%) rename bootstrap/templates/ansible/{ => shared}/playbooks/cluster-rollout-update.yaml.j2 (100%) rename bootstrap/templates/{ => k0s}/k0s-config.yaml.j2 (100%) diff --git a/.taskfiles/K0sTasks.yaml b/.taskfiles/K0sTasks.yaml index 6b13081f..9242fbb4 100644 --- a/.taskfiles/K0sTasks.yaml +++ b/.taskfiles/K0sTasks.yaml @@ -23,6 +23,10 @@ tasks: reset: desc: Resets the k0s cluster - cmd: k0sctl reset --config k0s-config.yaml + cmds: + - k0sctl reset --config k0s-config.yaml + - task: :ansible:run playbook=cluster-nuke + vars: + playbook: cluster-nuke preconditions: - { msg: "k0s-config.yaml not found", sh: "test -f {{.ROOT_DIR}}/k0s-config.yaml" } diff --git a/bootstrap/configure.yaml b/bootstrap/configure.yaml index e3679f6d..3b409276 100644 --- a/bootstrap/configure.yaml +++ b/bootstrap/configure.yaml @@ -34,6 +34,7 @@ ansible.builtin.include_tasks: tasks/k0s/main.yaml - name: Template Ansible configuration + when: bootstrap_distribution == "k0s" or bootstrap_distribution == "k3s" ansible.builtin.include_tasks: tasks/ansible/main.yaml - name: Template Kubernetes configuration diff --git a/bootstrap/tasks/ansible/main.yaml b/bootstrap/tasks/ansible/main.yaml index 2bee0d44..0fc7d878 100644 --- a/bootstrap/tasks/ansible/main.yaml +++ b/bootstrap/tasks/ansible/main.yaml @@ -1,24 +1,33 @@ --- -- name: Ensure Kubernetes directories exist +- name: Ensure Ansible k3s 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/"] + with_community.general.filetree: + - "../templates/ansible/shared/" + - "../templates/ansible/{{ bootstrap_distribution }}/" - name: Template Ansible unencrypted files - when: item.state == 'file' and 'sops' not in item.path and '.DS_Store' not in item.path + when: + - "item.state == 'file'" + - "'sops' not in item.path" + - "'.DS_Store' not in item.path" ansible.builtin.template: src: "{{ item.src }}" dest: "{{ repository_path }}/ansible/{{ item.path | regex_replace('.j2$', '') }}" mode: "0644" - with_community.general.filetree: ["../templates/ansible/"] + with_community.general.filetree: + - "../templates/ansible/shared/" + - "../templates/ansible/{{ bootstrap_distribution }}/" - name: Template Ansible encrypted files block: - name: Template Ansible encrypted files - when: item.state == 'file' and 'sops' in item.path + when: + - "item.state == 'file'" + - "'sops' in item.path" community.sops.sops_encrypt: path: "{{ repository_path }}/ansible/{{ item.path | replace('.j2', '') }}" encrypted_regex: ^(data|stringData)$ @@ -26,5 +35,6 @@ content_yaml: "{{ lookup('ansible.builtin.template', item.src) | from_yaml }}" mode: "0644" force: true - with_community.general.filetree: ["../templates/ansible/"] - + with_community.general.filetree: + - "../templates/ansible/shared/" + - "../templates/ansible/{{ bootstrap_distribution }}/" diff --git a/bootstrap/tasks/k0s/main.yaml b/bootstrap/tasks/k0s/main.yaml index 5c2b5a10..bcb04e9c 100644 --- a/bootstrap/tasks/k0s/main.yaml +++ b/bootstrap/tasks/k0s/main.yaml @@ -1,6 +1,6 @@ --- - name: Template k0s configuration file ansible.builtin.template: - src: "templates/k0s-config.yaml.j2" + src: "templates/k0s/k0s-config.yaml.j2" dest: "{{ repository_path }}/k0s-config.yaml" mode: "0644" diff --git a/bootstrap/tasks/kubernetes/main.yaml b/bootstrap/tasks/kubernetes/main.yaml index 9c6f27ab..e46e1dc4 100644 --- a/bootstrap/tasks/kubernetes/main.yaml +++ b/bootstrap/tasks/kubernetes/main.yaml @@ -9,7 +9,7 @@ - name: Template Kubernetes unencrypted files when: - - item.state == 'file' + - "item.state == 'file'" - "'.DS_Store' not in item.path" - "'sops' not in item.path" - "'cluster-settings-user.yaml.j2' not in item.path" @@ -27,9 +27,9 @@ - name: Template Kubernetes user cluster settings when: - - item.state == 'file' + - "item.state == 'file'" - "'cluster-settings-user.yaml' in item.path" - - not cluster_settings_user.stat.exists + - "not cluster_settings_user.stat.exists" ansible.builtin.template: src: "{{ item.src }}" dest: "{{ repository_path }}/kubernetes/{{ item.path | regex_replace('.j2$', '') }}" @@ -43,9 +43,9 @@ - name: Template Kubernetes user cluster secrets when: - - item.state == 'file' + - "item.state == 'file'" - "'cluster-secrets-user.yaml' in item.path" - - not cluster_secrets_user.stat.exists + - "not cluster_secrets_user.stat.exists" ansible.builtin.template: src: "{{ item.src }}" dest: "{{ repository_path }}/kubernetes/{{ item.path | regex_replace('.j2$', '') }}" @@ -55,7 +55,9 @@ - name: Template Kubernetes encrypted files block: - name: Template Kubernetes encrypted files - when: item.state == 'file' and 'sops' in item.path + when: + - "item.state == 'file'" + - "'sops' in item.path" community.sops.sops_encrypt: path: "{{ repository_path }}/kubernetes/{{ item.path | replace('.j2', '') }}" encrypted_regex: ^(data|stringData)$ diff --git a/bootstrap/templates/ansible/inventory/host_vars/.gitkeep.j2 b/bootstrap/templates/ansible/k0s/.gitkeep.j2 similarity index 100% rename from bootstrap/templates/ansible/inventory/host_vars/.gitkeep.j2 rename to bootstrap/templates/ansible/k0s/.gitkeep.j2 diff --git a/bootstrap/templates/ansible/inventory/group_vars/kubernetes/main.yaml.j2 b/bootstrap/templates/ansible/k3s/inventory/group_vars/kubernetes/main.yaml.j2 similarity index 100% rename from bootstrap/templates/ansible/inventory/group_vars/kubernetes/main.yaml.j2 rename to bootstrap/templates/ansible/k3s/inventory/group_vars/kubernetes/main.yaml.j2 diff --git a/bootstrap/templates/ansible/inventory/group_vars/master/main.yaml.j2 b/bootstrap/templates/ansible/k3s/inventory/group_vars/master/main.yaml.j2 similarity index 100% rename from bootstrap/templates/ansible/inventory/group_vars/master/main.yaml.j2 rename to bootstrap/templates/ansible/k3s/inventory/group_vars/master/main.yaml.j2 diff --git a/bootstrap/templates/ansible/inventory/group_vars/worker/main.yaml.j2 b/bootstrap/templates/ansible/k3s/inventory/group_vars/worker/main.yaml.j2 similarity index 100% rename from bootstrap/templates/ansible/inventory/group_vars/worker/main.yaml.j2 rename to bootstrap/templates/ansible/k3s/inventory/group_vars/worker/main.yaml.j2 diff --git a/bootstrap/templates/ansible/playbooks/cluster-installation.yaml.j2 b/bootstrap/templates/ansible/k3s/playbooks/cluster-installation.yaml.j2 similarity index 100% rename from bootstrap/templates/ansible/playbooks/cluster-installation.yaml.j2 rename to bootstrap/templates/ansible/k3s/playbooks/cluster-installation.yaml.j2 diff --git a/bootstrap/templates/ansible/playbooks/cluster-kube-vip.yaml.j2 b/bootstrap/templates/ansible/k3s/playbooks/cluster-kube-vip.yaml.j2 similarity index 100% rename from bootstrap/templates/ansible/playbooks/cluster-kube-vip.yaml.j2 rename to bootstrap/templates/ansible/k3s/playbooks/cluster-kube-vip.yaml.j2 diff --git a/bootstrap/templates/ansible/playbooks/tasks/cilium.yaml.j2 b/bootstrap/templates/ansible/k3s/playbooks/tasks/cilium.yaml.j2 similarity index 100% rename from bootstrap/templates/ansible/playbooks/tasks/cilium.yaml.j2 rename to bootstrap/templates/ansible/k3s/playbooks/tasks/cilium.yaml.j2 diff --git a/bootstrap/templates/ansible/playbooks/tasks/coredns.yaml.j2 b/bootstrap/templates/ansible/k3s/playbooks/tasks/coredns.yaml.j2 similarity index 100% rename from bootstrap/templates/ansible/playbooks/tasks/coredns.yaml.j2 rename to bootstrap/templates/ansible/k3s/playbooks/tasks/coredns.yaml.j2 diff --git a/bootstrap/templates/ansible/playbooks/tasks/cruft.yaml.j2 b/bootstrap/templates/ansible/k3s/playbooks/tasks/cruft.yaml.j2 similarity index 100% rename from bootstrap/templates/ansible/playbooks/tasks/cruft.yaml.j2 rename to bootstrap/templates/ansible/k3s/playbooks/tasks/cruft.yaml.j2 diff --git a/bootstrap/templates/ansible/playbooks/tasks/kubeconfig.yaml.j2 b/bootstrap/templates/ansible/k3s/playbooks/tasks/kubeconfig.yaml.j2 similarity index 100% rename from bootstrap/templates/ansible/playbooks/tasks/kubeconfig.yaml.j2 rename to bootstrap/templates/ansible/k3s/playbooks/tasks/kubeconfig.yaml.j2 diff --git a/bootstrap/templates/ansible/playbooks/templates/custom-cilium-helmchart.yaml.j2.j2 b/bootstrap/templates/ansible/k3s/playbooks/templates/custom-cilium-helmchart.yaml.j2.j2 similarity index 100% rename from bootstrap/templates/ansible/playbooks/templates/custom-cilium-helmchart.yaml.j2.j2 rename to bootstrap/templates/ansible/k3s/playbooks/templates/custom-cilium-helmchart.yaml.j2.j2 diff --git a/bootstrap/templates/ansible/playbooks/templates/custom-cilium-l2.yaml.j2.j2 b/bootstrap/templates/ansible/k3s/playbooks/templates/custom-cilium-l2.yaml.j2.j2 similarity index 100% rename from bootstrap/templates/ansible/playbooks/templates/custom-cilium-l2.yaml.j2.j2 rename to bootstrap/templates/ansible/k3s/playbooks/templates/custom-cilium-l2.yaml.j2.j2 diff --git a/bootstrap/templates/ansible/playbooks/templates/custom-coredns-helmchart.yaml.j2.j2 b/bootstrap/templates/ansible/k3s/playbooks/templates/custom-coredns-helmchart.yaml.j2.j2 similarity index 100% rename from bootstrap/templates/ansible/playbooks/templates/custom-coredns-helmchart.yaml.j2.j2 rename to bootstrap/templates/ansible/k3s/playbooks/templates/custom-coredns-helmchart.yaml.j2.j2 diff --git a/bootstrap/templates/ansible/playbooks/templates/kube-vip-static-pod.yaml.j2.j2 b/bootstrap/templates/ansible/k3s/playbooks/templates/kube-vip-static-pod.yaml.j2.j2 similarity index 100% rename from bootstrap/templates/ansible/playbooks/templates/kube-vip-static-pod.yaml.j2.j2 rename to bootstrap/templates/ansible/k3s/playbooks/templates/kube-vip-static-pod.yaml.j2.j2 diff --git a/bootstrap/templates/ansible/.ansible-lint.j2 b/bootstrap/templates/ansible/shared/.ansible-lint.j2 similarity index 100% rename from bootstrap/templates/ansible/.ansible-lint.j2 rename to bootstrap/templates/ansible/shared/.ansible-lint.j2 diff --git a/bootstrap/templates/ansible/inventory/group_vars/kubernetes/supplemental.yaml.j2 b/bootstrap/templates/ansible/shared/inventory/group_vars/kubernetes/supplemental.yaml.j2 similarity index 100% rename from bootstrap/templates/ansible/inventory/group_vars/kubernetes/supplemental.yaml.j2 rename to bootstrap/templates/ansible/shared/inventory/group_vars/kubernetes/supplemental.yaml.j2 diff --git a/bootstrap/templates/ansible/shared/inventory/host_vars/.gitkeep.j2 b/bootstrap/templates/ansible/shared/inventory/host_vars/.gitkeep.j2 new file mode 100644 index 00000000..e69de29b diff --git a/bootstrap/templates/ansible/inventory/hosts.yaml.j2 b/bootstrap/templates/ansible/shared/inventory/hosts.yaml.j2 similarity index 100% rename from bootstrap/templates/ansible/inventory/hosts.yaml.j2 rename to bootstrap/templates/ansible/shared/inventory/hosts.yaml.j2 diff --git a/bootstrap/templates/ansible/playbooks/cluster-nuke.yaml.j2 b/bootstrap/templates/ansible/shared/playbooks/cluster-nuke.yaml.j2 similarity index 100% rename from bootstrap/templates/ansible/playbooks/cluster-nuke.yaml.j2 rename to bootstrap/templates/ansible/shared/playbooks/cluster-nuke.yaml.j2 diff --git a/bootstrap/templates/ansible/playbooks/cluster-prepare.yaml.j2 b/bootstrap/templates/ansible/shared/playbooks/cluster-prepare.yaml.j2 similarity index 100% rename from bootstrap/templates/ansible/playbooks/cluster-prepare.yaml.j2 rename to bootstrap/templates/ansible/shared/playbooks/cluster-prepare.yaml.j2 diff --git a/bootstrap/templates/ansible/playbooks/cluster-reboot.yaml.j2 b/bootstrap/templates/ansible/shared/playbooks/cluster-reboot.yaml.j2 similarity index 100% rename from bootstrap/templates/ansible/playbooks/cluster-reboot.yaml.j2 rename to bootstrap/templates/ansible/shared/playbooks/cluster-reboot.yaml.j2 diff --git a/bootstrap/templates/ansible/playbooks/cluster-rollout-update.yaml.j2 b/bootstrap/templates/ansible/shared/playbooks/cluster-rollout-update.yaml.j2 similarity index 100% rename from bootstrap/templates/ansible/playbooks/cluster-rollout-update.yaml.j2 rename to bootstrap/templates/ansible/shared/playbooks/cluster-rollout-update.yaml.j2 diff --git a/bootstrap/templates/k0s-config.yaml.j2 b/bootstrap/templates/k0s/k0s-config.yaml.j2 similarity index 100% rename from bootstrap/templates/k0s-config.yaml.j2 rename to bootstrap/templates/k0s/k0s-config.yaml.j2 diff --git a/bootstrap/vars/.gitignore b/bootstrap/vars/.gitignore index 35ba105e..961abf44 100644 --- a/bootstrap/vars/.gitignore +++ b/bootstrap/vars/.gitignore @@ -1,2 +1,3 @@ +# DO NOT REMOVE OR CHANGE THIS FILE addons.yaml config.yaml