Merge "Update ensure-helm role to add more functionality"
This commit is contained in:
@@ -1,7 +1,22 @@
|
||||
Ensure Helm is installed
|
||||
|
||||
Currently, this role always downloads and installs the requested version
|
||||
of helm.
|
||||
|
||||
**Role Variables**
|
||||
|
||||
.. 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.
|
||||
|
||||
@@ -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_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]") }}
|
||||
|
||||
@@ -1,23 +1,58 @@
|
||||
---
|
||||
- name: Download Helm
|
||||
unarchive:
|
||||
remote_src: true
|
||||
src: "https://get.helm.sh/helm-v{{ helm_version }}-linux-amd64.tar.gz"
|
||||
dest: /tmp
|
||||
- name: Create a temporary directory for downloading helm
|
||||
ansible.builtin.tempfile:
|
||||
state: directory
|
||||
register: helm_download_dir
|
||||
|
||||
- name: Install Helm
|
||||
become: true
|
||||
copy:
|
||||
- name: Fetch the latest helm version (if needed)
|
||||
ansible.builtin.uri:
|
||||
url: "{{ helm_release_repo_url }}/helm-latest-version"
|
||||
return_content: true
|
||||
retries: 2
|
||||
delay: 15
|
||||
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
|
||||
src: /tmp/linux-amd64/helm
|
||||
dest: /usr/local/bin/helm
|
||||
mode: '0755'
|
||||
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
|
||||
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
|
||||
# initialization is needed anymore
|
||||
when: helm_version is version('3', '<')
|
||||
when: helm_download_version is version('3', '<')
|
||||
tags:
|
||||
# NOTE(mnaser): The `helm` module does not support running init only.
|
||||
- skip_ansible_lint
|
||||
|
||||
Reference in New Issue
Block a user