local/roles/yq/tasks/Debian.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

39 lines
1.0 KiB
YAML

---
- name: get latest github release
uri:
url: https://api.github.com/repos/mikefarah/yq/releases/latest
headers: '{{github_auth_headers}}'
register: latest
- set_fact:
asset_query: '[?contains(name, `yq_linux_amd64`)] | [0]'
assets: '{{latest.json.assets}}'
latest_version: '{{latest.json.tag_name[1:]}}'
yq_exe: '{{ansible_env.HOME}}/.local/bin/yq'
- name: check if already installed
stat:
path: '{{yq_exe}}'
register: yq_stat
- name: get installed version
when: yq_stat.stat.exists == True
command: '{{yq_exe}} --version'
register: yq_version_output
changed_when: false
- when: yq_stat.stat.exists == True
set_fact:
installed_version:
'{{yq_version_output.stdout.strip() | regex_replace("^.*(\d+\.\d+\.\d+).*$", "\1")}}'
- set_fact:
asset: '{{assets | to_json | from_json | json_query(asset_query)}}'
- name: download executable
when: installed_version is not defined or installed_version != latest_version
get_url:
url: '{{asset.browser_download_url}}'
dest: '{{yq_exe}}'
mode: +x