38 lines
1.0 KiB
YAML
38 lines
1.0 KiB
YAML
---
|
|
- name: get latest github release
|
|
uri:
|
|
url: https://api.github.com/repos/mikefarah/yq/releases/latest
|
|
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 alreayd 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
|