-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
# handlers file for thtong.github-tag-release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
localhost | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
- hosts: localhost | ||
roles: | ||
- thtong.github-tag-release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) }}" |