Merge "Update ensure-helm role to add more functionality"

This commit is contained in:
Zuul
2025-11-26 20:30:41 +00:00
committed by Gerrit Code Review
3 changed files with 86 additions and 15 deletions

View File

@@ -1,7 +1,22 @@
Ensure Helm is installed Ensure Helm is installed
Currently, this role always downloads and installs the requested version
of helm.
**Role Variables** **Role Variables**
.. zuul:rolevar:: helm_version .. zuul:rolevar:: helm_version
:default: 2.17.0
Version of Helm to install Version of Helm to install. For historical reasons this does not include
the "v" prefix. Use "latest" to probe for the latest release.
.. zuul:rolevar:: helm_release_repo_url
:default: https://get.helm.sh
The repo where the helm releases should be fetched from.
.. zuul:rolevar:: helm_install_dir
:default: /usr/local/bin
The installation directory for helm.

View File

@@ -1,2 +1,23 @@
--- ---
# These are reasonable overrides for users of the role and are part of the
# stable interface.
helm_version: 2.17.0 helm_version: 2.17.0
helm_release_repo_url: https://get.helm.sh
helm_install_dir: /usr/local/bin
# These defaults are not part of the stable interface for the role.
helm_archive_url: "{{ helm_release_repo_url }}/{{ helm_archive_name }}"
helm_arch: >-
{{ "amd64" if ansible_architecture == "x86_64"
else ansible_architecture }}
helm_system: >-
{{ ansible_system | lower }}
helm_download_version: >-
{{ helm_version if helm_version != "latest" else helm_latest_version }}
helm_archive_name: >-
helm-v{{ helm_download_version }}-{{ helm_system }}-{{ helm_arch }}.tar.gz
# We always need to lazy evaluate this value even if we don't use it.
# This value won't make sense unless the query task has run.
helm_latest_version: >-
{{ helm_latest_version_query.content | default("")
| regex_search("[0-9].*[0-9]") }}

View File

@@ -1,23 +1,58 @@
--- ---
- name: Download Helm - name: Create a temporary directory for downloading helm
unarchive: ansible.builtin.tempfile:
remote_src: true state: directory
src: "https://get.helm.sh/helm-v{{ helm_version }}-linux-amd64.tar.gz" register: helm_download_dir
dest: /tmp
- name: Install Helm - name: Fetch the latest helm version (if needed)
become: true ansible.builtin.uri:
copy: url: "{{ helm_release_repo_url }}/helm-latest-version"
remote_src: true return_content: true
src: /tmp/linux-amd64/helm retries: 2
dest: /usr/local/bin/helm delay: 15
mode: '0755' register: helm_latest_version_query
until: helm_latest_version_query is not failed
when: helm_version == "latest"
- name: Download and extract the helm binary
vars:
helm_archive_path: >-
{{ [helm_download_dir.path, helm_archive_name]
| ansible.builtin.path_join }}
block:
- name: Fetch the helm binary archive
ansible.builtin.uri:
url: "{{ helm_archive_url }}"
dest: "{{ helm_archive_path }}"
mode: "0644"
retries: 2
delay: 15
register: result
until: result is not failed
- name: Extract the helm binary from the archive
ansible.builtin.unarchive:
src: "{{ helm_archive_path }}"
dest: "{{ helm_install_dir }}"
mode: "0755"
remote_src: true
extra_opts:
- --strip=1
- --wildcards
- "*/helm"
become: true
- name: Remove the temporary helm download dir
ansible.builtin.file:
path: "{{ helm_download_dir.path }}"
state: absent
when: helm_download_dir.path is defined
- name: Initialize Helm - name: Initialize Helm
shell: helm init --client-only ansible.builtin.shell: helm init --client-only
# NOTE(b.schanzel): The init command was removed with helm v3 and no # NOTE(b.schanzel): The init command was removed with helm v3 and no
# initialization is needed anymore # initialization is needed anymore
when: helm_version is version('3', '<') when: helm_download_version is version('3', '<')
tags: tags:
# NOTE(mnaser): The `helm` module does not support running init only. # NOTE(mnaser): The `helm` module does not support running init only.
- skip_ansible_lint - skip_ansible_lint