2022-06-24 22:50:44 +00:00
|
|
|
- name: Create folder structure(s)
|
|
|
|
ansible.builtin.file:
|
|
|
|
path: "{{ item }}"
|
|
|
|
state: directory
|
|
|
|
loop:
|
2022-06-26 15:54:19 +00:00
|
|
|
- /opt/metacluster/helm-charts
|
2022-11-08 07:54:33 +00:00
|
|
|
- /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 }}
|
2022-07-06 14:09:21 +00:00
|
|
|
- /opt/metacluster/container-images
|
2022-06-30 09:20:39 +00:00
|
|
|
|
2022-06-24 22:50:44 +00:00
|
|
|
- name: Add helm repositories
|
|
|
|
kubernetes.core.helm_repository:
|
2022-06-24 22:54:36 +00:00
|
|
|
name: "{{ item.name }}"
|
2022-06-24 22:50:44 +00:00
|
|
|
repo_url: "{{ item.url }}"
|
|
|
|
state: present
|
2022-06-26 15:54:19 +00:00
|
|
|
loop: "{{ platform.helm_repositories }}"
|
|
|
|
|
|
|
|
- name: Fetch helm charts
|
|
|
|
ansible.builtin.command:
|
2022-06-26 19:20:16 +00:00
|
|
|
cmd: helm fetch {{ item.value.helm.chart }} --untar --version {{ item.value.helm.version }}
|
2022-06-26 15:54:19 +00:00
|
|
|
chdir: /opt/metacluster/helm-charts
|
2022-11-06 12:23:14 +00:00
|
|
|
when: item.value.helm is defined
|
2022-06-26 15:54:19 +00:00
|
|
|
loop: "{{ lookup('ansible.builtin.dict', components) }}"
|
2022-06-26 18:56:45 +00:00
|
|
|
loop_control:
|
|
|
|
label: "{{ item.key }}"
|
2022-06-26 15:54:19 +00:00
|
|
|
|
2022-07-09 07:18:13 +00:00
|
|
|
- block:
|
2022-07-09 07:26:13 +00:00
|
|
|
|
|
|
|
- name: Aggregate chart_values into dict
|
|
|
|
ansible.builtin.set_fact:
|
2022-07-11 11:37:55 +00:00
|
|
|
chart_values: "{{ chart_values | default({}) | combine({ (item.key | regex_replace('[^A-Za-z0-9]', '')): { 'chart_values': (item.value.helm.chart_values | from_yaml) } }) }}"
|
2022-07-09 21:37:57 +00:00
|
|
|
when: item.value.helm.chart_values is defined
|
2022-07-09 07:26:13 +00:00
|
|
|
loop: "{{ lookup('ansible.builtin.dict', components) }}"
|
|
|
|
loop_control:
|
|
|
|
label: "{{ item.key }}"
|
|
|
|
|
2022-07-09 21:37:57 +00:00
|
|
|
- name: Write dict to vars_file
|
2022-07-11 07:24:04 +00:00
|
|
|
ansible.builtin.copy:
|
|
|
|
dest: /opt/firstboot/ansible/vars/metacluster.yml
|
2022-11-08 13:43:40 +00:00
|
|
|
content: "{{ { 'components': (chart_values | combine({ 'clusterapi': components.clusterapi })) } | to_nice_yaml(indent=2, width=4096) }}"
|
2022-07-04 11:26:35 +00:00
|
|
|
|
2022-10-17 09:13:13 +00:00
|
|
|
- block:
|
|
|
|
|
2022-11-06 12:23:14 +00:00
|
|
|
- name: Download ClusterAPI manifests
|
2022-10-17 09:13:13 +00:00
|
|
|
ansible.builtin.get_url:
|
2022-11-07 12:28:44 +00:00
|
|
|
url: "{{ item.url }}"
|
2022-11-06 12:23:14 +00:00
|
|
|
dest: /opt/metacluster/manifests/{{ item.dest }}
|
|
|
|
register: clusterapi_manifests
|
|
|
|
loop:
|
|
|
|
# This list is based on `clusterctl config repositories`
|
2022-11-09 15:43:49 +00:00
|
|
|
# Note: Each manifest also needs a `metadata.yaml` file stored in the respective folder
|
2022-11-08 07:54:33 +00:00
|
|
|
- url: https://github.com/kubernetes-sigs/cluster-api/releases/download/{{ components.clusterapi.management.version.base }}/bootstrap-components.yaml
|
|
|
|
dest: bootstrap-kubeadm/{{ components.clusterapi.management.version.base }}/bootstrap-components.yaml
|
|
|
|
- url: https://github.com/kubernetes-sigs/cluster-api/releases/download/{{ components.clusterapi.management.version.base }}/core-components.yaml
|
|
|
|
dest: cluster-api/{{ components.clusterapi.management.version.base }}/core-components.yaml
|
|
|
|
- url: https://github.com/kubernetes-sigs/cluster-api/releases/download/{{ components.clusterapi.management.version.base }}/control-plane-components.yaml
|
|
|
|
dest: control-plane-kubeadm/{{ components.clusterapi.management.version.base }}/control-plane-components.yaml
|
2022-11-09 15:43:49 +00:00
|
|
|
# This downloads the same `metadata.yaml` file to three separate folders
|
2022-11-08 07:54:33 +00:00
|
|
|
- url: https://github.com/kubernetes-sigs/cluster-api/releases/download/{{ components.clusterapi.management.version.base }}/metadata.yaml
|
|
|
|
dest: bootstrap-kubeadm/{{ components.clusterapi.management.version.base }}/metadata.yaml
|
|
|
|
- url: https://github.com/kubernetes-sigs/cluster-api/releases/download/{{ components.clusterapi.management.version.base }}/metadata.yaml
|
|
|
|
dest: cluster-api/{{ components.clusterapi.management.version.base }}/metadata.yaml
|
|
|
|
- url: https://github.com/kubernetes-sigs/cluster-api/releases/download/{{ components.clusterapi.management.version.base }}/metadata.yaml
|
|
|
|
dest: control-plane-kubeadm/{{ components.clusterapi.management.version.base }}/metadata.yaml
|
2022-11-09 15:43:49 +00:00
|
|
|
# The vsphere infrastructure provider requires multiple files (`cluster-template.yaml` and `metadata.yaml` on top of default files)
|
|
|
|
- url: https://github.com/kubernetes-sigs/cluster-api-provider-vsphere/releases/download/{{ components.clusterapi.management.version.infrastructure_vsphere }}/infrastructure-components.yaml
|
|
|
|
dest: infrastructure-vsphere/{{ components.clusterapi.management.version.infrastructure_vsphere }}/infrastructure-components.yaml
|
|
|
|
- url: https://github.com/kubernetes-sigs/cluster-api-provider-vsphere/releases/download/{{ components.clusterapi.management.version.infrastructure_vsphere }}/cluster-template.yaml
|
|
|
|
dest: infrastructure-vsphere/{{ components.clusterapi.management.version.infrastructure_vsphere }}/cluster-template.yaml
|
|
|
|
- url: https://github.com/kubernetes-sigs/cluster-api-provider-vsphere/releases/download/{{ components.clusterapi.management.version.infrastructure_vsphere }}/metadata.yaml
|
|
|
|
dest: infrastructure-vsphere/{{ components.clusterapi.management.version.infrastructure_vsphere }}/metadata.yaml
|
2022-11-07 12:28:44 +00:00
|
|
|
# Additionally, cert-manager is a prerequisite
|
2022-11-08 07:54:33 +00:00
|
|
|
- url: https://github.com/cert-manager/cert-manager/releases/download/{{ components.clusterapi.management.version.cert_manager }}/cert-manager.yaml
|
|
|
|
dest: cert-manager/{{ components.clusterapi.management.version.cert_manager }}/cert-manager.yaml
|
2022-10-17 12:28:59 +00:00
|
|
|
loop_control:
|
2022-11-06 12:23:14 +00:00
|
|
|
label: "{{ item.url | basename }}"
|
2022-11-14 08:36:13 +00:00
|
|
|
retries: 5
|
|
|
|
delay: 5
|
|
|
|
until: clusterapi_manifests is not failed
|
2022-10-17 09:13:13 +00:00
|
|
|
|
2022-11-07 00:57:30 +00:00
|
|
|
- name: Parse manifests
|
|
|
|
ansible.builtin.shell:
|
|
|
|
cmd: cat {{ item.dest }} | yq --no-doc eval '.. | .image? | select(.)' | awk '!/ /' | sort
|
|
|
|
register: parsedmanifests
|
2022-11-07 01:18:54 +00:00
|
|
|
loop: "{{ clusterapi_manifests.results }}"
|
2022-11-07 00:57:30 +00:00
|
|
|
loop_control:
|
2022-11-07 01:39:51 +00:00
|
|
|
label: "{{ item.dest | basename }}"
|
2022-10-17 09:13:13 +00:00
|
|
|
|
2022-11-07 00:57:30 +00:00
|
|
|
- name: Store container images
|
|
|
|
ansible.builtin.set_fact:
|
2022-11-07 13:06:34 +00:00
|
|
|
clusterapi_containerimages: "{{ parsedmanifests | json_query('results[*].stdout_lines') | select() | flatten }}"
|
|
|
|
|
2022-10-17 19:30:06 +00:00
|
|
|
- name: Parse helm charts for container images
|
|
|
|
ansible.builtin.shell:
|
|
|
|
cmd: "{{ item.value.helm.parse_logic }}"
|
|
|
|
chdir: /opt/metacluster/helm-charts/{{ item.key }}
|
|
|
|
register: containerimages
|
2022-11-07 03:18:20 +00:00
|
|
|
when: item.value.helm is defined
|
2022-10-17 19:30:06 +00:00
|
|
|
loop: "{{ lookup('ansible.builtin.dict', components) }}"
|
|
|
|
loop_control:
|
|
|
|
label: "{{ item.key }}"
|
2022-10-17 19:03:13 +00:00
|
|
|
|
2022-06-29 11:07:34 +00:00
|
|
|
- name: Pull and store containerimages
|
2022-07-06 14:32:39 +00:00
|
|
|
ansible.builtin.shell:
|
2022-07-06 12:36:30 +00:00
|
|
|
cmd: >-
|
|
|
|
skopeo copy \
|
2022-07-27 12:23:33 +00:00
|
|
|
--insecure-policy \
|
2022-07-06 14:09:21 +00:00
|
|
|
--retry-times=5 \
|
2022-07-06 12:36:30 +00:00
|
|
|
docker://{{ item }} \
|
2022-11-17 07:35:00 +00:00
|
|
|
docker-archive:./{{ ( item | regex_findall('[^/:]+'))[-2] }}_{{ uid }}.tar:{{ item }}
|
2022-06-29 11:07:34 +00:00
|
|
|
chdir: /opt/metacluster/container-images
|
2022-11-17 08:22:58 +00:00
|
|
|
vars:
|
2022-11-17 07:35:00 +00:00
|
|
|
uid: "{{ lookup('ansible.builtin.password', '/dev/null length=5 chars=ascii_lowercase,digits seed=item') }}"
|
2022-11-07 06:38:01 +00:00
|
|
|
loop: "{{ ((containerimages.results | map(attribute='stdout_lines') | select('defined') | flatten) + dependencies.container_images + (clusterapi_containerimages | list)) | unique }}"
|
2022-07-15 10:14:12 +00:00
|
|
|
|
2022-07-18 10:09:54 +00:00
|
|
|
# - name: Inject manifests
|
|
|
|
# ansible.builtin.template:
|
|
|
|
# src: "{{ item.type }}.j2"
|
|
|
|
# dest: /var/lib/rancher/k3s/server/manifests/{{ item.name }}-manifest.yaml
|
|
|
|
# owner: root
|
|
|
|
# group: root
|
|
|
|
# mode: 0600
|
|
|
|
# loop: "{{ lookup('ansible.builtin.dict', components) | map(attribute='value.manifests') | list | select('defined') | flatten }}"
|
|
|
|
# loop_control:
|
|
|
|
# label: "{{ item.type + '/' + item.name }}"
|