From c27712bc209bfd84fe3c9553e81afb0e4447445c Mon Sep 17 00:00:00 2001 From: Danny Bessems Date: Thu, 24 Nov 2022 10:59:41 +0100 Subject: [PATCH] Simplify playbook roles --- ansible/playbook.yml | 3 +- ansible/roles/appliance/tasks/main.yml | 2 -- .../tasks/containerimages.yml} | 35 +------------------ .../tasks/dependencies.archive_compressed.yml | 0 .../tasks/dependencies.yml | 7 ---- ansible/roles/assets/tasks/git.yml | 5 +++ ansible/roles/assets/tasks/helm.yml | 19 ++++++++++ .../{metacluster => assets}/tasks/k3s.yml | 8 ----- ansible/roles/assets/tasks/main.yml | 24 +++++++++++++ ansible/roles/assets/tasks/nodetemplates.yml | 4 +++ .../templates/helmchartconfig.j2 | 0 .../workloadcluster/tasks/clusterapi.yml | 4 +-- ansible/roles/metacluster/tasks/main.yml | 8 ----- ansible/roles/metacluster/tasks/staging.yml | 18 ---------- 14 files changed, 56 insertions(+), 81 deletions(-) delete mode 100644 ansible/roles/appliance/tasks/main.yml rename ansible/roles/{metacluster/tasks/components.yml => assets/tasks/containerimages.yml} (81%) rename ansible/roles/{appliance => assets}/tasks/dependencies.archive_compressed.yml (100%) rename ansible/roles/{appliance => assets}/tasks/dependencies.yml (91%) create mode 100644 ansible/roles/assets/tasks/git.yml create mode 100644 ansible/roles/assets/tasks/helm.yml rename ansible/roles/{metacluster => assets}/tasks/k3s.yml (83%) create mode 100644 ansible/roles/assets/tasks/main.yml create mode 100644 ansible/roles/assets/tasks/nodetemplates.yml rename ansible/roles/{metacluster => assets}/templates/helmchartconfig.j2 (100%) delete mode 100644 ansible/roles/metacluster/tasks/main.yml delete mode 100644 ansible/roles/metacluster/tasks/staging.yml diff --git a/ansible/playbook.yml b/ansible/playbook.yml index a4bf947..d0763e8 100644 --- a/ansible/playbook.yml +++ b/ansible/playbook.yml @@ -7,5 +7,4 @@ roles: - os - firstboot - - appliance - - metacluster + - assets diff --git a/ansible/roles/appliance/tasks/main.yml b/ansible/roles/appliance/tasks/main.yml deleted file mode 100644 index 97a5cc2..0000000 --- a/ansible/roles/appliance/tasks/main.yml +++ /dev/null @@ -1,2 +0,0 @@ -- name: Install & configure dependencies - import_tasks: dependencies.yml diff --git a/ansible/roles/metacluster/tasks/components.yml b/ansible/roles/assets/tasks/containerimages.yml similarity index 81% rename from ansible/roles/metacluster/tasks/components.yml rename to ansible/roles/assets/tasks/containerimages.yml index 4648328..311e609 100644 --- a/ansible/roles/metacluster/tasks/components.yml +++ b/ansible/roles/assets/tasks/containerimages.yml @@ -1,36 +1,3 @@ -- name: Create folder structure(s) - ansible.builtin.file: - path: "{{ item }}" - state: directory - loop: - - /opt/metacluster/helm-charts - - /opt/metacluster/manifests/bootstrap-kubeadm/{{ components.clusterapi.management.version.base }} - - /opt/metacluster/manifests/cert-manager/{{ components.clusterapi.management.version.cert_manager }} - - /opt/metacluster/manifests/cluster-api/{{ components.clusterapi.management.version.base }} - - /opt/metacluster/manifests/control-plane-kubeadm/{{ components.clusterapi.management.version.base }} - - /opt/metacluster/manifests/infrastructure-vsphere/{{ components.clusterapi.management.version.infrastructure_vsphere }} - - /opt/metacluster/container-images - -- name: Add helm repositories - kubernetes.core.helm_repository: - name: "{{ item.name }}" - repo_url: "{{ item.url }}" - state: present - loop: "{{ platform.helm_repositories }}" - -- name: Fetch helm charts - ansible.builtin.command: - cmd: helm fetch {{ item.value.helm.chart }} --untar --version {{ item.value.helm.version }} - chdir: /opt/metacluster/helm-charts - when: item.value.helm is defined - register: helmcharts - loop: "{{ lookup('ansible.builtin.dict', components) }}" - loop_control: - label: "{{ item.key }}" - retries: 5 - delay: 5 - until: helmcharts is not failed - - block: - name: Aggregate chart_values into dict @@ -51,7 +18,7 @@ - name: Download ClusterAPI manifests ansible.builtin.get_url: url: "{{ item.url }}" - dest: /opt/metacluster/manifests/{{ item.dest }} + dest: /opt/metacluster/cluster-api/{{ item.dest }} register: clusterapi_manifests loop: # This list is based on `clusterctl config repositories` diff --git a/ansible/roles/appliance/tasks/dependencies.archive_compressed.yml b/ansible/roles/assets/tasks/dependencies.archive_compressed.yml similarity index 100% rename from ansible/roles/appliance/tasks/dependencies.archive_compressed.yml rename to ansible/roles/assets/tasks/dependencies.archive_compressed.yml diff --git a/ansible/roles/appliance/tasks/dependencies.yml b/ansible/roles/assets/tasks/dependencies.yml similarity index 91% rename from ansible/roles/appliance/tasks/dependencies.yml rename to ansible/roles/assets/tasks/dependencies.yml index dee2ce2..cd36247 100644 --- a/ansible/roles/appliance/tasks/dependencies.yml +++ b/ansible/roles/assets/tasks/dependencies.yml @@ -1,10 +1,3 @@ -# - name: Create folder structure(s) -# ansible.builtin.file: -# path: "{{ item }}" -# state: directory -# loop: -# - /foo - - name: Download & install static binaries ansible.builtin.get_url: url: "{{ item.url }}" diff --git a/ansible/roles/assets/tasks/git.yml b/ansible/roles/assets/tasks/git.yml new file mode 100644 index 0000000..f4d2f8f --- /dev/null +++ b/ansible/roles/assets/tasks/git.yml @@ -0,0 +1,5 @@ +- name: Clone git repository + ansible.builtin.git: + repo: "{{ platform.gitops.repository.uri }}" + version: "{{ platform.gitops.repository.revision }}" + dest: /opt/metacluster/git-repositories/gitops diff --git a/ansible/roles/assets/tasks/helm.yml b/ansible/roles/assets/tasks/helm.yml new file mode 100644 index 0000000..f03d073 --- /dev/null +++ b/ansible/roles/assets/tasks/helm.yml @@ -0,0 +1,19 @@ +- name: Add helm repositories + kubernetes.core.helm_repository: + name: "{{ item.name }}" + repo_url: "{{ item.url }}" + state: present + loop: "{{ platform.helm_repositories }}" + +- name: Fetch helm charts + ansible.builtin.command: + cmd: helm fetch {{ item.value.helm.chart }} --untar --version {{ item.value.helm.version }} + chdir: /opt/metacluster/helm-charts + when: item.value.helm is defined + register: helmcharts + loop: "{{ lookup('ansible.builtin.dict', components) }}" + loop_control: + label: "{{ item.key }}" + retries: 5 + delay: 5 + until: helmcharts is not failed diff --git a/ansible/roles/metacluster/tasks/k3s.yml b/ansible/roles/assets/tasks/k3s.yml similarity index 83% rename from ansible/roles/metacluster/tasks/k3s.yml rename to ansible/roles/assets/tasks/k3s.yml index 2c5d606..06ff1bf 100644 --- a/ansible/roles/metacluster/tasks/k3s.yml +++ b/ansible/roles/assets/tasks/k3s.yml @@ -1,11 +1,3 @@ -- name: Create folder structure(s) - ansible.builtin.file: - path: "{{ item }}" - state: directory - loop: - - /var/lib/rancher/k3s/agent/images - - /var/lib/rancher/k3s/server/manifests - - /opt/metacluster/k3s - name: Download & install K3s binary ansible.builtin.get_url: diff --git a/ansible/roles/assets/tasks/main.yml b/ansible/roles/assets/tasks/main.yml new file mode 100644 index 0000000..8b72dfc --- /dev/null +++ b/ansible/roles/assets/tasks/main.yml @@ -0,0 +1,24 @@ +- name: Create folder structure(s) + ansible.builtin.file: + path: "{{ item }}" + state: directory + loop: + - /opt/metacluster/cluster-api/bootstrap-kubeadm/{{ components.clusterapi.management.version.base }} + - /opt/metacluster/cluster-api/cert-manager/{{ components.clusterapi.management.version.cert_manager }} + - /opt/metacluster/cluster-api/cluster-api/{{ components.clusterapi.management.version.base }} + - /opt/metacluster/cluster-api/control-plane-kubeadm/{{ components.clusterapi.management.version.base }} + - /opt/metacluster/cluster-api/infrastructure-vsphere/{{ components.clusterapi.management.version.infrastructure_vsphere }} + - /opt/metacluster/container-images + - /opt/metacluster/git-repositories/gitops + - /opt/metacluster/helm-charts + - /opt/metacluster/k3s + - /opt/workloadcluster/node-templates + - /var/lib/rancher/k3s/agent/images + - /var/lib/rancher/k3s/server/manifests + +- import_tasks: dependencies.yml +- import_tasks: k3s.yml +- import_tasks: helm.yml +- import_tasks: git +- import_tasks: containerimages.yml +- import_tasks: nodetemplates.yml diff --git a/ansible/roles/assets/tasks/nodetemplates.yml b/ansible/roles/assets/tasks/nodetemplates.yml new file mode 100644 index 0000000..53119b3 --- /dev/null +++ b/ansible/roles/assets/tasks/nodetemplates.yml @@ -0,0 +1,4 @@ +- name: Download node-template image + ansible.builtin.uri: + url: "{{ components.clusterapi.workload.node_template.url }}" + dest: /opt/workloadcluster/node-templates/{{ components.clusterapi.workload.node_template.name }} diff --git a/ansible/roles/metacluster/templates/helmchartconfig.j2 b/ansible/roles/assets/templates/helmchartconfig.j2 similarity index 100% rename from ansible/roles/metacluster/templates/helmchartconfig.j2 rename to ansible/roles/assets/templates/helmchartconfig.j2 diff --git a/ansible/roles/firstboot/files/ansible_payload/roles/workloadcluster/tasks/clusterapi.yml b/ansible/roles/firstboot/files/ansible_payload/roles/workloadcluster/tasks/clusterapi.yml index 14d9b41..456ad31 100644 --- a/ansible/roles/firstboot/files/ansible_payload/roles/workloadcluster/tasks/clusterapi.yml +++ b/ansible/roles/firstboot/files/ansible_payload/roles/workloadcluster/tasks/clusterapi.yml @@ -1,7 +1,7 @@ - name: Configure clusterctl ansible.builtin.template: src: clusterctl.j2 - dest: /opt/metacluster/manifests/clusterctl.yaml + dest: /opt/metacluster/cluster-api/clusterctl.yaml vars: _template: version: @@ -27,4 +27,4 @@ - name: Initialize Cluster API management cluster ansible.builtin.shell: cmd: clusterctl init -v5 -i vsphere:{{ components.clusterapi.management.version.infrastructure_vsphere }} --config ./clusterctl.yaml --kubeconfig {{ kubeconfig.path }} - chdir: /opt/metacluster/manifests + chdir: /opt/metacluster/cluster-api diff --git a/ansible/roles/metacluster/tasks/main.yml b/ansible/roles/metacluster/tasks/main.yml deleted file mode 100644 index 6fbad2e..0000000 --- a/ansible/roles/metacluster/tasks/main.yml +++ /dev/null @@ -1,8 +0,0 @@ -- name: Pre-stage K3s components - import_tasks: k3s.yml - -- name: Pre-stage meta-cluster components - import_tasks: components.yml - -- name: Pre-stage meta-cluster configuration and workload-cluster components - import_tasks: staging.yml diff --git a/ansible/roles/metacluster/tasks/staging.yml b/ansible/roles/metacluster/tasks/staging.yml deleted file mode 100644 index c56141e..0000000 --- a/ansible/roles/metacluster/tasks/staging.yml +++ /dev/null @@ -1,18 +0,0 @@ -- name: Create folder structure(s) - ansible.builtin.file: - path: "{{ item }}" - state: directory - loop: - - /opt/metacluster/git-repositories/gitops - - /opt/workloadcluster/node-templates - -- name: Clone git repository - ansible.builtin.git: - repo: "{{ platform.gitops.repository.uri }}" - version: "{{ platform.gitops.repository.revision }}" - dest: /opt/metacluster/git-repositories/gitops - -- name: Download node-template image - ansible.builtin.uri: - url: "{{ components.clusterapi.workload.node_template.url }}" - dest: /opt/workloadcluster/node-templates/{{ components.clusterapi.workload.node_template.name }}