Skip to content

Commit 05f7530

Browse files
jrosserJonathan Rossermnaser
authored
Download binaries (#139)
* Add version to helm-diff download destination * Add utility playbook to download required binaries for all roles Usage: ansible-playbook vexxhost.kubernetes.download_binaries -e target=localhost This playbook uses the existing download_artifact role and downloads all versions of all binaries required for all roles. Pass extra variables with -e as required to configure download_artifact. * Add zuul jobs for playbooks/download_binaries.yml * ci: move molecule scenario Signed-off-by: Mohammed Naser <[email protected]> * ci: fix scenario name Signed-off-by: Mohammed Naser <[email protected]> * ci: fix scenario name Signed-off-by: Mohammed Naser <[email protected]> * ci: fix job Signed-off-by: Mohammed Naser <[email protected]> * ci: revert python version Signed-off-by: Mohammed Naser <[email protected]> * fix: allow usage with non-root user Signed-off-by: Mohammed Naser <[email protected]> --------- Signed-off-by: Mohammed Naser <[email protected]> Co-authored-by: Jonathan Rosser <[email protected]> Co-authored-by: Mohammed Naser <[email protected]>
1 parent 3a5ca03 commit 05f7530

File tree

7 files changed

+126
-2
lines changed

7 files changed

+126
-2
lines changed

.python-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.13
1+
3.10

.zuul.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@
134134
# failures for now, so set as non-voting for now.
135135
voting: false
136136

137+
- job:
138+
name: ansible-collection-kubernetes-molecule-download-binaries
139+
parent: ansible-collection-kubernetes-molecule
140+
vars:
141+
molecule_scenario: download-binaries
142+
137143
- job:
138144
name: ansible-collection-kubernetes-molecule-ha
139145
parent: ansible-collection-kubernetes-molecule
@@ -169,6 +175,7 @@
169175
- ansible-collection-kubernetes-molecule-bgp
170176
- ansible-collection-kubernetes-molecule-cluster-api
171177
- ansible-collection-kubernetes-molecule-cluster-upgrade
178+
- ansible-collection-kubernetes-molecule-download-binaries
172179
- ansible-collection-kubernetes-molecule-ha
173180
- ansible-collection-kubernetes-molecule-helm
174181
- ansible-collection-kubernetes-molecule-upload-helm-chart
@@ -183,6 +190,7 @@
183190
- ansible-collection-kubernetes-molecule-bgp
184191
- ansible-collection-kubernetes-molecule-cluster-api
185192
- ansible-collection-kubernetes-molecule-cluster-upgrade
193+
- ansible-collection-kubernetes-molecule-download-binaries
186194
- ansible-collection-kubernetes-molecule-ha
187195
- ansible-collection-kubernetes-molecule-helm
188196
- ansible-collection-kubernetes-molecule-upload-helm-chart
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Copyright (c) 2024 BBC R&D, Inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
- name: include playbook
5+
ansible.builtin.import_playbook: vexxhost.kubernetes.download_binaries
6+
vars:
7+
target: all
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright (c) 2025 VEXXHOST, Inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
ansible:
5+
cfg:
6+
defaults:
7+
callbacks_enabled: ansible.posix.profile_tasks
8+
deprecation_warnings: false
9+
connection:
10+
pipelining: true
11+
executor:
12+
backend: ansible-playbook
13+
args:
14+
ansible_playbook:
15+
- --inventory=${MOLECULE_PROJECT_DIRECTORY}/inventory.yaml
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright (c) 2023 BBC R&D, Inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
- name: Verify
5+
hosts: all
6+
become: true
7+
vars:
8+
dir: /var/lib/downloads
9+
tasks:
10+
- name: Stat target dir
11+
ansible.builtin.stat:
12+
path: "{{ dir }}"
13+
register: _dir_stat
14+
15+
- name: Assert that target dir is created
16+
ansible.builtin.assert:
17+
that:
18+
- _dir_stat.stat.exists
19+
- _dir_stat.stat.isdir
20+
21+
- name: Find target files
22+
ansible.builtin.find:
23+
paths: "{{ dir }}"
24+
register: _dir_find
25+
26+
- name: Assert that some files were downloaded
27+
ansible.builtin.assert:
28+
that:
29+
- _dir_find.matched > 0

playbooks/download_binaries.yml

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

roles/helm/defaults/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ helm_diff_checksums:
3838
v3.8.1: d451e4772a3987710f485de4caed760583c88f8f15864a623b3fbd73be7077ec
3939

4040
helm_diff_download_url: "https://github.com/databus23/helm-diff/releases/download/{{ helm_diff_version }}/helm-diff-{{ ansible_facts['system'] | lower }}-{{ download_artifact_goarch }}.tgz" # noqa: yaml[line-length]
41-
helm_diff_download_dest: "{{ download_artifact_work_directory }}/helm-diff-{{ ansible_facts['system'] | lower }}-{{ download_artifact_goarch }}.tgz"
41+
helm_diff_download_dest: "{{ download_artifact_work_directory }}/helm-diff-{{ helm_diff_version }}-{{ ansible_facts['system'] | lower }}-{{ download_artifact_goarch }}.tgz" # noqa: yaml[line-length]
4242
helm_diff_checksum: "{{ helm_diff_checksums[download_artifact_goarch][helm_diff_version] }}"

0 commit comments

Comments
 (0)