93 lines
3.4 KiB
YAML
93 lines
3.4 KiB
YAML
- name: Create folder structure(s)
|
|
ansible.builtin.file:
|
|
path: "{{ item }}"
|
|
state: directory
|
|
loop:
|
|
- /opt/metacluster/helm-charts
|
|
- /opt/metacluster/manifests
|
|
- /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
|
|
loop: "{{ lookup('ansible.builtin.dict', components) }}"
|
|
loop_control:
|
|
label: "{{ item.key }}"
|
|
|
|
- block:
|
|
|
|
- name: Aggregate chart_values into dict
|
|
ansible.builtin.set_fact:
|
|
chart_values: "{{ chart_values | default({}) | combine({ (item.key | regex_replace('[^A-Za-z0-9]', '')): { '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:
|
|
label: "{{ item.key }}"
|
|
|
|
- name: Write dict to vars_file
|
|
ansible.builtin.copy:
|
|
dest: /opt/firstboot/ansible/vars/metacluster.yml
|
|
content: "{{ { 'components': chart_values } | to_nice_yaml(indent=2, width=4096) }}"
|
|
|
|
- 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
|
|
loop: "{{ lookup('ansible.builtin.dict', components) }}"
|
|
loop_control:
|
|
label: "{{ item.key }}"
|
|
|
|
- block:
|
|
|
|
- name: Retrieve Cluster-API manifests
|
|
ansible.builtin.shell:
|
|
cmd: clusterctl config repositories | awk '/CoreProvider|kubeadm|vsphere/ {print $(NF-1)"download/"$NF}'
|
|
register: clusterapi_manifests
|
|
|
|
- name: Download manifests
|
|
ansible.builtin.get_url:
|
|
url: "{{ item }}"
|
|
dest: "/opt/metacluster/manifests/{{ item | basename }}"
|
|
loop: "{{ clusterapi_manifests.stdout_lines }}"
|
|
|
|
- name: Parse manifests
|
|
ansible.builtin.shell:
|
|
cmd: cat {{ item }} | yq --no-doc eval '.. | .image? | select(.)' | awk '!/ /' | sort
|
|
register: parsedmanifests
|
|
loop: "{{ query('ansible.builtin.fileglob', '/opt/metacluster/manifests/*.yaml') | sort }}"
|
|
|
|
- name: Store container images
|
|
ansible.builtin.set_fact:
|
|
clusterapi_containerimages: parsedmanifests.results | json_query('results[*].stdout')
|
|
|
|
- name: Pull and store containerimages
|
|
ansible.builtin.shell:
|
|
cmd: >-
|
|
skopeo copy \
|
|
--insecure-policy \
|
|
--retry-times=5 \
|
|
docker://{{ item }} \
|
|
docker-archive:./{{ ( item | regex_findall('[^/:]+'))[-2] }}.tar:{{ item }}
|
|
chdir: /opt/metacluster/container-images
|
|
loop: "{{ ((containerimages.results | map(attribute='stdout_lines') | flatten) + dependencies.container_images + clusterapi_containerimages) | unique }}"
|
|
|
|
# - 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 }}"
|