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

使用Ansible uri模块下载MySQL Server二进制文件失败求助

解决Ansible uri模块下载MySQL二进制文件403禁止问题

我尝试通过Ansible uri模块下载MySQL Server二进制文件,但执行失败,错误信息如下:

TASK [mysql : Download MySQL Server]

fatal: [server1 -> localhost]: FAILED! => {"cache_control": "max-age=0, no-cache, no-store", "changed": false, "connection": "close", "content_length": "4530", "content_type": "text/html", "date": "Thu, 27 Apr 2023 10:27:05 GMT", "elapsed": 0, "etag": ""46491460e504640b96a3f5e60da0945f:1434117667"", "expires": "Thu, 27 Apr 2023 10:27:05 GMT", "msg": "Status code was 403 and not [200]: HTTP Error 403: Forbidden", "path": "/home//code//roles/mysql/files/mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz", "pragma": "no-cache", "redirected": false, "server": "AkamaiNetStorage", "set_cookie": "AK_NETWORKTYPE=ESSL; expires=Thu, 27-Apr-2023 10:29:05 GMT", "status": 403, "url": "https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz"}

我的Ansible任务配置:

uri:
  url: https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz
  method: GET
  follow_redirects: safe
  dest: /some/path/

我已经尝试过follow_redirects参数的所有允许值,但问题依旧。不过通过命令行执行curl命令可以成功下载:

curl -L https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz

解决思路

  • 添加User-Agent请求头:Akamai CDN会验证请求的User-Agent标识,curl默认自带合法的User-Agent,而uri模块默认的标识可能被拦截。在uri任务中添加自定义请求头:
    uri:
      url: https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz
      method: GET
      follow_redirects: all
      dest: /some/path/
      headers:
        User-Agent: "curl/7.68.0"
    
  • 替换为get_url模块:Ansible的get_url模块专为文件下载设计,处理重定向和请求头的逻辑更适配这类场景,配置示例:
    get_url:
      url: https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz
      dest: /some/path/
      headers:
        User-Agent: "curl/7.68.0"
      follow_redirects: all
    
  • 手动解析重定向:先对原URL发送HEAD请求获取真实跳转地址,再用uri模块请求该地址下载,避免CDN的拦截逻辑。
  • 验证本地路径权限:确保dest指定的目录存在且Ansible执行用户拥有写入权限,排除本地路径问题干扰。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.23 15:05:00