Skip to content

Instantly share code, notes, and snippets.

@mikroskeem
Created March 16, 2024 07:19
Show Gist options
  • Save mikroskeem/10089b91dbd8f2af6dc62f1093c513ed to your computer and use it in GitHub Desktop.
Save mikroskeem/10089b91dbd8f2af6dc62f1093c513ed to your computer and use it in GitHub Desktop.
Download a private GitHub release using Ansible
---
- name: "Download a private GitHub release"
vars:
owner: "mikroskeem"
repo: "snakeoil"
tag: "v0.0.1"
asset_name: "snakeoil.x86_64-linux"
get_url_args:
dest: "/tmp/the-thing"
github_pat: "{{ lookup('env', 'GH_TOKEN') }}"
block:
- name: "Obtain GitHub release details"
ansible.builtin.uri:
url: "https://api.github.com/repos/{{ owner }}/{{ repo }}/releases/tags/{{ tag }}"
return_content: true
use_netrc: "{{ github_pat | default(false) is falsy }}"
headers:
"accept": "application/vnd.github.v3+json"
"authorization": "{{ 'token ' + github_pat if github_pat | default('') else None }}"
"x-github-api-version": "2022-11-28"
register: "_gh_release"
- name: "Download release from GitHub"
vars:
gh_release_asset_url: "{{ _gh_release.json.assets | selectattr('name', 'equalto', asset_name) | map(attribute='url') | first }}"
ansible.builtin.get_url:
url: "{{ gh_release_asset_url }}"
dest: "{{ get_url_args.dest | mandatory }}"
owner: "{{ get_url_args.owner | default(None) }}"
group: "{{ get_url_args.group | default(None) }}"
mode: "{{ get_url_args.mode | default(None) }}"
use_netrc: "{{ github_pat | default(false) is falsy }}"
headers:
"accept": "application/octet-stream"
"authorization": "{{ 'token ' + github_pat if github_pat | default('') else None }}"
"x-github-api-version": "2022-11-28"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment