From 2b56677e9a18c0165c88e46be8f930dbbf8abfe0 Mon Sep 17 00:00:00 2001 From: Danny Bessems Date: Wed, 5 Apr 2023 10:47:17 +0200 Subject: [PATCH] Remove regex_replace filter;Refactor dict key names;Make chart values optional --- ansible/roles/assets/tasks/manifests.yml | 4 ++-- .../bootstrap/roles/metacluster/tasks/git.yml | 2 +- .../bootstrap/roles/metacluster/tasks/gitops.yml | 2 +- .../bootstrap/roles/metacluster/tasks/registry.yml | 2 +- .../bootstrap/roles/metacluster/tasks/storage.yml | 2 +- .../bootstrap/roles/workloadcluster/tasks/gitops.yml | 10 +++++++++- .../upgrade/roles/metacluster/tasks/git.yml | 2 +- .../upgrade/roles/metacluster/tasks/gitops.yml | 2 +- .../upgrade/roles/metacluster/tasks/registry.yml | 2 +- .../upgrade/roles/metacluster/tasks/storage.yml | 2 +- ansible/vars/workloadcluster.yml | 4 ++-- 11 files changed, 21 insertions(+), 13 deletions(-) diff --git a/ansible/roles/assets/tasks/manifests.yml b/ansible/roles/assets/tasks/manifests.yml index e845e1f..29e13e2 100644 --- a/ansible/roles/assets/tasks/manifests.yml +++ b/ansible/roles/assets/tasks/manifests.yml @@ -2,7 +2,7 @@ - name: Aggregate chart_values into dict ansible.builtin.set_fact: - metacluster_chartvalues: "{{ metacluster_chartvalues | default({}) | combine({ (item.key | regex_replace('[^A-Za-z0-9]', '')): { 'chart_values': (item.value.helm.chart_values | from_yaml) } }) }}" + metacluster_chartvalues: "{{ metacluster_chartvalues | default({}) | combine({ item.key: { 'chart_values': (item.value.helm.chart_values | from_yaml) } }) }}" when: item.value.helm.chart_values is defined loop: "{{ lookup('ansible.builtin.dict', components) }}" loop_control: @@ -22,7 +22,7 @@ - name: Aggregate chart_values into dict ansible.builtin.set_fact: - workloadcluster_chartvalues: "{{ workloadcluster_chartvalues | default({}) | combine({ (item.key | regex_replace('[^A-Za-z0-9]', '')): { 'chart_values': (item.value.chart_values | from_yaml) } }) }}" + workloadcluster_chartvalues: "{{ workloadcluster_chartvalues | default({}) | combine({ item.key: { 'chart_values': (item.value.chart_values | from_yaml) } }) }}" when: item.value.chart_values is defined loop: "{{ lookup('ansible.builtin.dict', downstream.helm_charts) }}" loop_control: diff --git a/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/metacluster/tasks/git.yml b/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/metacluster/tasks/git.yml index 85decc5..3da8e60 100644 --- a/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/metacluster/tasks/git.yml +++ b/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/metacluster/tasks/git.yml @@ -8,7 +8,7 @@ create_namespace: true wait: false kubeconfig: "{{ kubeconfig.path }}" - values: "{{ components.gitea.chart_values }}" + values: "{{ components['gitea'].chart_values }}" - name: Ensure gitea API availability ansible.builtin.uri: diff --git a/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/metacluster/tasks/gitops.yml b/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/metacluster/tasks/gitops.yml index 6ff1531..5948034 100644 --- a/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/metacluster/tasks/gitops.yml +++ b/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/metacluster/tasks/gitops.yml @@ -8,7 +8,7 @@ create_namespace: true wait: false kubeconfig: "{{ kubeconfig.path }}" - values: "{{ components.argocd.chart_values }}" + values: "{{ components['argo-cd'].chart_values }}" - name: Ensure argo-cd API availability ansible.builtin.uri: diff --git a/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/metacluster/tasks/registry.yml b/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/metacluster/tasks/registry.yml index 6589b12..fe4a99d 100644 --- a/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/metacluster/tasks/registry.yml +++ b/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/metacluster/tasks/registry.yml @@ -8,7 +8,7 @@ create_namespace: true wait: false kubeconfig: "{{ kubeconfig.path }}" - values: "{{ components.harbor.chart_values }}" + values: "{{ components['harbor'].chart_values }}" - name: Ensure harbor API availability ansible.builtin.uri: diff --git a/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/metacluster/tasks/storage.yml b/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/metacluster/tasks/storage.yml index 059e0a7..17c8f15 100644 --- a/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/metacluster/tasks/storage.yml +++ b/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/metacluster/tasks/storage.yml @@ -7,7 +7,7 @@ create_namespace: true wait: false kubeconfig: "{{ kubeconfig.path }}" - values: "{{ components.longhorn.chart_values }}" + values: "{{ components['longhorn'].chart_values }}" - name: Ensure longhorn API availability ansible.builtin.uri: diff --git a/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/workloadcluster/tasks/gitops.yml b/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/workloadcluster/tasks/gitops.yml index b20253a..f57e181 100644 --- a/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/workloadcluster/tasks/gitops.yml +++ b/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/workloadcluster/tasks/gitops.yml @@ -13,10 +13,18 @@ loop_control: label: "{{ item.path | basename }}" +- name: Create subfolders + ansible.builtin.file: + path: /opt/workloadcluster/git-repositories/gitops/values/{{ item.key }} + state: directory + loop: "{{ lookup('ansible.builtin.dict', downstream_components) }}" + loop_control: + label: "{{ item.key }}" + - name: Write chart values to file ansible.builtin.copy: dest: /opt/workloadcluster/git-repositories/gitops/values/{{ item.key }}/values.yaml - content: "{{ item.value.chart_values }}" + content: "{{ item.value.chart_values | default('# Empty') }}" loop: "{{ lookup('ansible.builtin.dict', downstream_components) }}" loop_control: label: "{{ item.key }}" diff --git a/ansible/roles/firstboot/files/ansible_payload/upgrade/roles/metacluster/tasks/git.yml b/ansible/roles/firstboot/files/ansible_payload/upgrade/roles/metacluster/tasks/git.yml index 9970549..2454039 100644 --- a/ansible/roles/firstboot/files/ansible_payload/upgrade/roles/metacluster/tasks/git.yml +++ b/ansible/roles/firstboot/files/ansible_payload/upgrade/roles/metacluster/tasks/git.yml @@ -7,7 +7,7 @@ release_namespace: gitea wait: false kubeconfig: "{{ kubeconfig.path }}" - values: "{{ components.gitea.chart_values }}" + values: "{{ components['gitea'].chart_values }}" - name: Ensure gitea API availability ansible.builtin.uri: diff --git a/ansible/roles/firstboot/files/ansible_payload/upgrade/roles/metacluster/tasks/gitops.yml b/ansible/roles/firstboot/files/ansible_payload/upgrade/roles/metacluster/tasks/gitops.yml index ada716e..79e4ea7 100644 --- a/ansible/roles/firstboot/files/ansible_payload/upgrade/roles/metacluster/tasks/gitops.yml +++ b/ansible/roles/firstboot/files/ansible_payload/upgrade/roles/metacluster/tasks/gitops.yml @@ -7,7 +7,7 @@ release_namespace: argo-cd wait: false kubeconfig: "{{ kubeconfig.path }}" - values: "{{ components.argocd.chart_values }}" + values: "{{ components['argo-cd'].chart_values }}" - name: Ensure argo-cd API availability ansible.builtin.uri: diff --git a/ansible/roles/firstboot/files/ansible_payload/upgrade/roles/metacluster/tasks/registry.yml b/ansible/roles/firstboot/files/ansible_payload/upgrade/roles/metacluster/tasks/registry.yml index e433a87..9005a2b 100644 --- a/ansible/roles/firstboot/files/ansible_payload/upgrade/roles/metacluster/tasks/registry.yml +++ b/ansible/roles/firstboot/files/ansible_payload/upgrade/roles/metacluster/tasks/registry.yml @@ -7,7 +7,7 @@ release_namespace: harbor wait: false kubeconfig: "{{ kubeconfig.path }}" - values: "{{ components.harbor.chart_values }}" + values: "{{ components['harbor'].chart_values }}" - name: Ensure harbor API availability ansible.builtin.uri: diff --git a/ansible/roles/firstboot/files/ansible_payload/upgrade/roles/metacluster/tasks/storage.yml b/ansible/roles/firstboot/files/ansible_payload/upgrade/roles/metacluster/tasks/storage.yml index 93861e4..280a6ae 100644 --- a/ansible/roles/firstboot/files/ansible_payload/upgrade/roles/metacluster/tasks/storage.yml +++ b/ansible/roles/firstboot/files/ansible_payload/upgrade/roles/metacluster/tasks/storage.yml @@ -34,7 +34,7 @@ release_namespace: longhorn-system wait: false kubeconfig: "{{ kubeconfig.path }}" - values: "{{ components.longhorn.chart_values }}" + values: "{{ components['longhorn'].chart_values }}" - name: Ensure longhorn API availability ansible.builtin.uri: diff --git a/ansible/vars/workloadcluster.yml b/ansible/vars/workloadcluster.yml index 9a09c14..99c8f6e 100644 --- a/ansible/vars/workloadcluster.yml +++ b/ansible/vars/workloadcluster.yml @@ -22,5 +22,5 @@ downstream: chart: sealed-secrets/sealed-secrets namespace: sealed-secrets parse_logic: helm template . | yq --no-doc eval '.. | .image? | select(.)' | sort -u | awk '!/ /' - chart_values: !unsafe | - # Empty + # chart_values: !unsafe | + # # Empty