|
| 1 | +- name: Download all binaries required at runtime for ansible-collection-kubernetes |
| 2 | + hosts: "{{ target | default('all') }}" |
| 3 | + gather_facts: false |
| 4 | + vars: |
| 5 | + # some role defaults use vars only defined in the download_artifact role |
| 6 | + _download_artifact_goarch_groups: |
| 7 | + x86_64: amd64 |
| 8 | + aarch64: arm64 |
| 9 | + armv7l: arm |
| 10 | + |
| 11 | + download_artifact_goarch: >- |
| 12 | + {%- if ansible_facts['architecture'] in _download_artifact_goarch_groups -%} |
| 13 | + {{ _download_artifact_goarch_groups[ansible_facts['architecture']] }} |
| 14 | + {%- else -%} |
| 15 | + {{ ansible_facts['architecture'] }} |
| 16 | + {%- endif -%} |
| 17 | +
|
| 18 | + download_artifact_work_directory: /var/lib/downloads |
| 19 | + |
| 20 | + role_location: "{{ playbook_dir }}/../roles" |
| 21 | + tasks: |
| 22 | + - name: Gather minimal facts |
| 23 | + ansible.builtin.setup: |
| 24 | + gather_subset: min |
| 25 | + delegate_to: localhost |
| 26 | + |
| 27 | + - name: Find all subdirectories in the role location |
| 28 | + ansible.builtin.find: |
| 29 | + file_type: directory |
| 30 | + paths: "{{ role_location }}" |
| 31 | + recurse: true |
| 32 | + register: role_paths |
| 33 | + delegate_to: localhost |
| 34 | + |
| 35 | + - name: Select only defaults/ directories and load vars |
| 36 | + # also load vars from download_artifact to get architecture mappings |
| 37 | + ansible.builtin.include_vars: |
| 38 | + dir: "{{ item }}" |
| 39 | + with_items: |
| 40 | + - "{{ role_paths.files | selectattr('path', 'search', 'defaults') | map(attribute='path') }}" |
| 41 | + delegate_to: localhost |
| 42 | + |
| 43 | + - name: Generate list of all binaries for all roles |
| 44 | + vexxhost.containers.binary_downloads: |
| 45 | + prefixes: "{{ query('varnames', '_download_url$') | map('replace', '_download_url', '') }}" |
| 46 | + register: binaries |
| 47 | + delegate_to: localhost |
| 48 | + |
| 49 | + - name: Include download_artifact role |
| 50 | + ansible.builtin.include_role: |
| 51 | + name: vexxhost.containers.download_artifact |
| 52 | + vars: |
| 53 | + download_artifact_url: "{{ item.url }}" |
| 54 | + download_artifact_dest: "{{ item.dest }}" |
| 55 | + download_artifact_checksum: "sha256:{{ item.checksum }}" |
| 56 | + download_artifact_owner: "{{ ansible_user }}" |
| 57 | + download_artifact_mode: "0755" |
| 58 | + download_artifact_unarchive: false |
| 59 | + download_artifact_no_log: false |
| 60 | + with_items: "{{ binaries.downloads }}" |
0 commit comments