You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Ansible从GitHub私有项目下载最新发布的二进制文件

问题原因

你遇到的问题本质是两个配置缺失导致的:

  1. GitHub私有仓库的Release附件下载链接会返回302重定向到AWS S3的临时资源地址,Ansible的get_url模块默认会把认证请求头随重定向转发给S3,S3不识别GitHub的私有仓库认证头,会直接返回400/403错误。
  2. 你手动传Authorization头时没有补全认证前缀,或使用用户名密码认证时没有限制重定向时的头传递规则。

可用配置示例

方式1:使用GitHub PAT做Basic认证(推荐)

GitHub的Basic认证规则中,用户名可以填写任意非空值,密码位填写你的个人访问令牌(PAT)即可,注意PAT需要提前授予repo权限:

- name: Download binary from Github
  get_url:
    url: "https://github.com/myproject/releases/download/main-db24b21d/binary"
    dest: "/home/user/server"
    force_basic_auth: yes
    username: "github_username" # 可填任意非空值
    password: "your_github_pat"
    follow_redirects: safe
    # 核心配置:重定向时不传递Authorization头到S3
    redirect_headers_allowlist: [] # Ansible 2.11+ 适用
    # Ansible 2.10及更早版本替换为:
    # http_agent_redirect_headers: []

方式2:直接传递预编码的Basic认证头(和你curl用法一致)

如果你要完全对齐现有curl命令的逻辑,直接传已经base64编码的认证token,用以下配置:

- name: Download binary from Github
  get_url:
    url: "https://github.com/myproject/releases/download/main-db24b21d/binary"
    dest: "/home/user/server"
    follow_redirects: safe
    redirect_headers_allowlist: []
    headers:
      # 注意不要漏了Basic后的空格,<token>替换为你curl中使用的编码后值
      Authorization: "Basic <token>"

内容的提问来源于stack exchange,提问作者Can

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.03 02:36:02