Tud*_*dor 3 url automation github download ansible
使用Ansible,请告知我如何从Github存储库下载最新版本的二进制文件。根据我目前的理解,这些步骤将是:获取最新版本的网址b。下载版本
为一个。我有一些类似的东西没有提供实际的版本(例如v0.11.53):
- name: get latest Gogs release
local_action:
module: uri
url: https://github.com/gogits/gogs/releases/latest
method: GET
follow_redirects: no
status_code: 301
register: release_url
Run Code Online (Sandbox Code Playgroud)
对于b。我有下面的工作,但需要不断更新。除了版本,我需要在a中设置一个变量:
- name: download latest
become: yes
become-user: "{{gogs_user}}"
get_url:
url: https://github.com/gogs/gogs/releases/download/v0.11.53/linux_amd64.tar.gz
dest: "/home/{{gogs_user}}/linux_amd64.tar.gz"
Run Code Online (Sandbox Code Playgroud)
谢谢!
小智 10
另一种方法是使用 ansible github_release 模块获取最新标签
例子
- name: Get gogs latest tag
github_release:
user: gogs
repo: gogs
action: latest_release
register: gogs_latest
- name: Grab gogs latest binaries
unarchive:
src: "https://github.com/gogs/gogs/releases/download/{{ gogs_latest['tag'] }}/gogs_{{ gogs_latest['tag'] | regex_replace('^v','') }}_linux_amd64.zip"
dest: /usr/local/bin
remote_src: true
Run Code Online (Sandbox Code Playgroud)
我正在使用以下方法watchexec从 GitHub 版本下载和提取最新的 Linux 二进制文件。
- hosts: localhost
tasks:
- name: check latest watchexec
uri:
url: https://api.github.com/repos/watchexec/watchexec/releases/latest
return_content: true
register: watchexec_latest
- name: "installing watchexec {{ watchexec_latest.json.tag_name }}"
loop: "{{ watchexec_latest.json.assets }}"
when: "'x86_64-unknown-linux-musl.tar.xz' in item.name"
unarchive:
remote_src: yes
src: "{{ item.browser_download_url }}"
dest: "{{ ansible_env.HOME }}/bin/"
keep_newer: yes
extra_opts:
- --strip=1
- --no-anchored
- watchexec
Run Code Online (Sandbox Code Playgroud)
tar extra_opts在这里解释。
每次调用剧本时,这仍然会下载二进制文件。作为改进,可以使用与解压文件对应的set_fact缓存node_id属性。
Github有一个API用于操作已记录的发行版。
因此,假设您想获取ansible的最新版本(属于ansible项目),您将
https://api.github.com/repos/ansible/ansible/releases/latestRun Code Online (Sandbox Code Playgroud){ "url": "https://api.github.com/repos/ansible/ansible/releases/5120666", "assets_url": "https://api.github.com/repos/ansible/ansible/releases/5120666/assets", "upload_url": "https://uploads.github.com/repos/ansible/ansible/releases/5120666/assets{?name,label}", "html_url": "https://github.com/ansible/ansible/releases/tag/v2.2.1.0-0.3.rc3", "id": 5120666, "node_id": "MDc6UmVsZWFzZTUxMjA2NjY=", "tag_name": "v2.2.1.0-0.3.rc3", "target_commitish": "devel", "name": "THESE ARE NOT OUR OFFICIAL RELEASES", ... }, "prerelease": false, "created_at": "2017-01-09T16:49:01Z", "published_at": "2017-01-10T20:09:37Z", "assets": [ ], "tarball_url": "https://api.github.com/repos/ansible/ansible/tarball/v2.2.1.0-0.3.rc3", "zipball_url": "https://api.github.com/repos/ansible/ansible/zipball/v2.2.1.0-0.3.rc3", "body": "For official tarballs go to https://releases.ansible.com\n" }
tarball_url在会做的ansible代码中
- hosts: localhost
tasks:
- uri:
url: https://api.github.com/repos/ansible/ansible/releases/latest
return_content: true
register: json_reponse
- get_url:
url: "{{ json_reponse.json.tarball_url }}"
dest: ./ansible-latest.tar.gz
Run Code Online (Sandbox Code Playgroud)
我让您调整适当的参数来回答您的问题:)