Skip to content

Instantly share code, notes, and snippets.

@b-mc
Created November 23, 2021 12:52
Show Gist options
  • Save b-mc/630626771cf45dcd33d9221d166af93f to your computer and use it in GitHub Desktop.
Save b-mc/630626771cf45dcd33d9221d166af93f to your computer and use it in GitHub Desktop.
Ansible: download the latest release asset from GitHub

Ansible: download the latest release asset from GitHub

About

Node Exporter (Linux amd64) is the example here. Note: you might need to_json|from_json as a workaround for this issue.

Play

- name: get the latest release details
  uri:
    url: https://api.github.com/repos/prometheus/node_exporter/releases/latest
    method: GET
  register: node_exp_release
  delegate_to: localhost

- name: set the release facts
  set_fact:
    file_name: "{{ node_exp_latest.name }}"
    download_url: "{{ node_exp_latest.browser_download_url }}"
  vars:
    node_exp_latest: "{{ node_exp_release.json|to_json|from_json|json_query('assets[?ends_with(name,`linux-amd64.tar.gz`)]')|first }}"

- name: download the latest release
  get_url:
    url: "{{ download_url }}"
    dest: /tmp/

Facts

ok: [host] => {
    "ansible_facts": {
        "download_url": "https://github.com/prometheus/node_exporter/releases/download/v1.3.0/node_exporter-1.3.0.linux-amd64.tar.gz",
        "file_name": "node_exporter-1.3.0.linux-amd64.tar.gz"
    },
    "changed": false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment