Ansible - 从 Github 存储库下载最新版本的二进制文件 [英] Ansible - Download latest release binary from Github repo
问题描述
使用 Ansible,请告知我如何从 Github 存储库下载最新版本的二进制文件.根据我目前的理解,步骤是:一种.获取最新版本的 URL湾下载版本
对于一个.我有类似的东西不提供实际版本(例如 v0.11.53):
- 名称:获取最新的 Gogs 版本本地操作:模块:uri网址:https://github.com/gogits/gogs/releases/latest方法:获取follow_redirects: 没有状态代码:301注册:release_url
对于 b.我有以下工作但需要不断更新.我需要在 a. 中设置一个变量而不是版本:
- 名称:下载最新的变成:是成为用户:{{gogs_user}}"获取网址:网址:https://github.com/gogs/gogs/releases/download/v0.11.53/linux_amd64.tar.gzdest: "/home/{{gogs_user}}/linux_amd64.tar.gz"
谢谢!
Github 有一个 API 来操作发布,它是 已记录.
假设您想获得最新版本的 ansible(属于 ansible 项目)
- 调用url
https://api.github.com/repos/ansible/ansible/releases/latest
- 得到一个像这样的 json 结构
<代码>{"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",身份证":5120666,"node_id": "MDc6UmVsZWFzZTUxMjA2NjY=","tag_name": "v2.2.1.0-0.3.rc3","target_commitish": "开发","name": "这些不是我们的官方版本",...},预发行":假,"created_at": "2017-01-09T16:49:01Z","published_at": "2017-01-10T20:09:37Z",资产":[],"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": "官方压缩包请访问 https://releases.ansible.com\n"}
- 获取键值
tarball_url
- 下载上面检索到的密钥的值
在可以做的 ansible 代码中
- 主机:本地主机任务:- uri:网址:https://api.github.com/repos/ansible/ansible/releases/latest返回内容:真注册:json_reponse- 获取网址:网址:{{ json_reponse.json.tarball_url }}"目标:./ansible-latest.tar.gz
我让你调整适当的参数来回答你的问题:)
With Ansible please advise how i could download the latest release binary from Github repository. As per my current understanding the steps would be: a. get URL of latest release b. download the release
For a. I have something like which does not provide the actual release (ex. 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
For b. I have the below which works but needs constant updating. Instead of version i would need a variable set in 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"
Thank you!
Github has an API to manipulate the release which is documented.
so imagine you want to get the latest release of ansible (which belong to the project ansible) you would
- call the url
https://api.github.com/repos/ansible/ansible/releases/latest
- get an json structure like this
{ "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" }
- get the value of the key
tarball_url
- download the value of the key retrieved just above
In ansible code that would do
- 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
I let you adapt the proper parameters to answer your question :)
这篇关于Ansible - 从 Github 存储库下载最新版本的二进制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!