Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
thtong committed Oct 4, 2021
1 parent 9b1b6b0 commit c0790a3
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 0 deletions.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# thtong.github-tag-release

Ansible role to download tagged/latest release from any GitHub repository

## Requirements

None.

## Role Variables

- gh_repo_name - the github repo e.g. `thtong/ansible-role-github-tag-release`
- gh_repo_tag - the tag e.g `latest`
- gh_repo_download_dir - the path to save the release asset e.g. `/tmp/`
- gh_repo_downnlod_mode - options are `architecture`, `first`, `all` (default), `match`
- architecture will download assets with name that match target OS architecture e.g. amd64
- first will download first asset listed
- all will download all assets listed
- match will download asset(s) that match the regex specified in `gh_repo_download_match_regex`
- gh_repo_download_match_regex - the regex to use if `gh_repo_downnlod_mode` is set to match

## Dependencies

None.

## Example Playbook

- hosts: localhost
roles:
- { role: thtong.github-tag-release, gh_repo_name: rfjakob/gocryptfs }

## License

BSD

## Author Information

An optional section for the role authors to include contact information, or a website (HTML is not allowed).
13 changes: 13 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
# defaults file for thtong.github-tag-release
gh_repo_name: thtong/ansible-role-github-tag-release
gh_repo_tag: latest
gh_repo_download_dir: /tmp/
gh_repo_download_mode: all
# options are:
# architecture - assets with name that match OS architecture e.g. amd64
# first - first one listed
# all - everything listed
# match - regex for name e.g. *.tar.gz
# if type is match, then regex below will be used
gh_repo_download_match_regex: ".*\\.tar\\.gz"
2 changes: 2 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# handlers file for thtong.github-tag-release
52 changes: 52 additions & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
galaxy_info:
author: your name
description: your role description
company: your company (optional)

# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker

# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc)

min_ansible_version: 2.1

# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:

#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99

galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.

dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.
30 changes: 30 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
# tasks file for thtong.github-tag-release
- name: "Get {{ gh_repo_name }} release details"
uri:
url: "https://api.github.com/repos/{{ gh_repo_name }}/releases/{{ (gh_repo_tag == 'latest') | ternary('latest', 'tags/' + gh_repo_tag) }}"
return_content: true
delegate_to: localhost
run_once: yes
register: gh_release

- name: "Get {{ gh_repo_tag }} {{ gh_repo_name }} download details"
set_fact:
gh_download_info_all: "{{ gh_release.json.assets | selectattr('browser_download_url', 'match', '.*') }}"
gh_download_info_first: "{{ gh_release.json.assets | selectattr('browser_download_url', 'match', '.*') | first }}"
gh_download_info_architecture: "{{ gh_release.json.assets | selectattr('browser_download_url', 'match', '.*' + go_arch + '.*') }}"
gh_download_info_match: "{{ gh_release.json.assets | selectattr('browser_download_url', 'match', gh_repo_download_match_regex) }}"
when:
- gh_release is succeeded

- name: "Download {{ gh_repo_tag }} {{ gh_repo_name }} assets"
get_url:
url: "{{ item.browser_download_url }}"
dest: "{{ gh_repo_download_dir }}"
timeout: 300
retries: 3
delay: 2
register: gh_download
loop: "{{ lookup('vars', 'gh_download_info_' + gh_repo_download_mode) }}"
when:
- lookup('vars', 'gh_download_info_' + gh_repo_download_mode) is defined
4 changes: 4 additions & 0 deletions tests/gocryptfs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
- hosts: localhost
roles:
- { role: thtong.github-tag-release, gh_repo_name: rfjakob/gocryptfs }
2 changes: 2 additions & 0 deletions tests/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
localhost

4 changes: 4 additions & 0 deletions tests/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
- hosts: localhost
roles:
- thtong.github-tag-release
11 changes: 11 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
# vars file for thtong.github-tag-release

go_arch_map:
i386: "386"
x86_64: "amd64"
aarch64: "arm64"
armv7l: "armv7"
armv6l: "armv6"

go_arch: "{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}"

0 comments on commit c0790a3

Please sign in to comment.