local/roles/yq/tasks/RedHat.yaml
Kenneth Benzie (Benie) e711b9f3b2 Add optional GitHub API authentication headers
If the `GITHUB_TOKEN` is defined in the Ansible controller's
environment it is used to set the GitHub REST API authentication header.
This is they passed to all `uri` modules tasks which interact with the
GitHub REST API. If the `GITHUB_TOKEN` is not set, the authentication
header is not used.

Fixes #19
2024-04-06 16:35:01 +01:00

53 lines
1.4 KiB
YAML

---
- name: stat executable
stat:
path: '{{ansible_env.HOME}}/.local/bin/yq'
register: yq_stat
- name: get installed version
when: yq_stat.stat.exists
command: yq --version
changed_when: false
register: yq_version
- name: extract installed version
when: yq_stat.stat.exists
set_fact:
yq_installed_version:
'{{yq_version.stdout.strip() | regex_replace("^.*(\d+\.\d+\.\d+).*$", "\1")}}'
- name: get latest release
uri:
url: 'https://api.github.com/repos/mikefarah/yq/releases/latest'
headers: '{{github_auth_headers}}'
register: latest
- name: determine if yq needs installed
set_fact:
yq_needs_installed:
'{{not yq_stat.stat.exists or yq_installed_version != latest.json.tag_name}}'
arch_dict: {x86_64: amd64, arm64: arm64}
- name: select asset name
when: yq_needs_installed
set_fact:
asset_query:
'[?contains(name, `yq_linux_{{arch_dict[ansible_architecture]}}`)] | [0]'
- name: select asset
when: yq_needs_installed
set_fact:
asset: '{{latest.json.assets | to_json | from_json | json_query(asset_query)}}'
- name: create directory
when: yq_needs_installed
file:
path: '{{ansible_env.HOME}}/.local/bin'
state: directory
- name: install executable
when: yq_needs_installed
get_url:
url: '{{asset.browser_download_url}}'
dest: '{{ansible_env.HOME}}/.local/bin/yq'
mode: '0755'