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-10-17 09:13:13 +00:00
|
|
|
- /opt/metacluster/manifests
|
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
|
|
|
|
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
|
|
|
|
content: "{{ { 'components': chart_values } | to_nice_yaml(indent=2, width=4096) }}"
|
2022-07-04 11:26:35 +00:00
|
|
|
|
2022-06-26 16:24:57 +00:00
|
|
|
- name: Parse helm charts for container images
|
2022-06-27 07:56:48 +00:00
|
|
|
ansible.builtin.shell:
|
2022-06-27 10:27:11 +00:00
|
|
|
cmd: "{{ item.value.helm.parse_logic }}"
|
2022-06-27 17:43:07 +00:00
|
|
|
chdir: /opt/metacluster/helm-charts/{{ item.key }}
|
2022-06-26 16:24:57 +00:00
|
|
|
register: containerimages
|
|
|
|
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-10-17 09:13:13 +00:00
|
|
|
- block:
|
|
|
|
|
|
|
|
- name: Retrieve Cluster-API manifests
|
|
|
|
ansible.builtin.command:
|
|
|
|
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')
|
|
|
|
|
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 }} \
|
|
|
|
docker-archive:./{{ ( item | regex_findall('[^/:]+'))[-2] }}.tar:{{ item }}
|
2022-06-29 11:07:34 +00:00
|
|
|
chdir: /opt/metacluster/container-images
|
2022-10-17 09:13:13 +00:00
|
|
|
loop: "{{ ((containerimages.results | map(attribute='stdout_lines') | flatten) + dependencies.container_images + clusterapi_containerimages) | 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 }}"
|