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

Ansible Tower通过Git仓库安装Collection同步报错求助

问题描述

我正按照Ansible官方文档尝试通过collections/requirements.yml文件安装自定义Collection,但遇到错误。

相关版本信息:

  • Tower版本:v3.8.6
  • Galaxy版本:v2.13.2

我的galaxy.yml文件内容:

---
namespace: my_ansible_collections
name: ansible_cert_renew_collection
version: 1.0.0
description: Collection of role to renew certs on servers
readme: readme.md
authors:
  - Myself
tags:
  - collection
  - certificate
repository: https://github.com/philthynz/ansible-collections.git

我的collections/requirements.yml文件内容:

---
collections:
  - name: my_ansible_collections.ansible_cert_renew_collection
    source: https://github.com/philthynz/ansible-collections.git
    type: git
    version: main

同步Tower项目时的报错信息:

TASK [fetch galaxy collections from collections/requirements.yml] **************
fatal: [localhost]: FAILED! => {"changed": false, "cmd": ["ansible-galaxy", "collection", "install", "-r", "collections/requirements.yml", "--collections-path", "/var/lib/awx/projects/.__awx_cache/_1449__tsp_certificate_renewals_phil/stage/requirements_collections"], "delta": "0:00:01.868622", "end": "2022-11-16 06:42:46.339223", "msg": "non-zero return code", "rc": 1, "start": "2022-11-16 06:42:44.470601", "stderr": "ERROR! Failed to parse Galaxy response from 'https://github.com/philthynz/ansible-collections' as JSON:\n\n\n\n\n\n\n\n<!DOCTYPE html>\n<html lang=\"en\" data-color-mode=\"auto\" data-light-theme=\"light\" data-dark-theme=\"dark\" data-a11y-animated-images=\"system\">\n  <head>\n    <meta charset=\"utf-8\">\n  <link rel=\"dns-prefetch\" href=\"https://github.githubassets.com\">\n  <link rel=\"dns-prefetch\" href=\"https://avatars.githubusercontent.com\">\n  <link rel=\"dns-prefetch\" href=\"https://github-cloud.s3.amazonaws.com\">\n  <link rel=\"dns-prefetch\" href=\"https://user-images.…

请问我哪里操作出错了?


问题分析与解决方法

核心错误原因

  1. 版本兼容性问题:Tower 3.8.6默认搭配的Ansible版本为2.9.x,而在requirements.yml中通过type: git参数从Git仓库安装Collection的语法是Ansible 2.10及以上版本才支持的。旧版ansible-galaxy无法识别该参数,错误地将Git仓库URL当作Galaxy API端点发起请求,返回的HTML页面自然无法解析为JSON,导致报错。
  2. 仓库结构或网络问题:另外需确认两点:一是Git仓库的结构是否正确(galaxy.yml需处于Collection根目录);二是Tower服务器是否能正常访问GitHub(无防火墙、代理拦截等问题)。

具体解决方法

方法1:使用命令行安装(适配旧版Ansible)

在Tower项目的**预执行脚本(Pre-run Script)**中添加以下命令,直接通过命令行安装Git仓库中的Collection:

ansible-galaxy collection install git+https://github.com/philthynz/ansible-collections.git,main -p /var/lib/awx/projects/your_project_path/collections

注意替换your_project_path为实际项目路径,也可使用--collections-path指定与报错中一致的缓存路径。

方法2:调整requirements.yml语法(需Ansible 2.10+支持)

如果能将Tower升级到支持Ansible 2.10+的版本(如Tower 3.9及以上),需根据仓库结构调整requirements.yml:

  • 若Collection在Git仓库根目录(galaxy.yml位于仓库根目录),保持现有语法即可,同时确保Tower能正常访问GitHub;
  • 若Collection在仓库内的子路径(如collections/my_ansible_collections/ansible_cert_renew_collection),需添加path参数指定路径:
---
collections:
  - name: my_ansible_collections.ansible_cert_renew_collection
    source: https://github.com/philthynz/ansible-collections.git
    type: git
    version: main
    path: collections/my_ansible_collections/ansible_cert_renew_collection

方法3:升级Tower版本

直接升级Tower到3.9及以上版本,该版本默认搭配的Ansible版本支持requirements.yml中type: git的语法,可直接使用现有配置完成安装。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.12 19:40:31