AWX同步Git/Bitbucket仓库失败:无法解析主机问题求助
问题
此前已配置并成功使用AWX项目与Bitbucket仓库同步,但近日同步时出现如下错误:
TASK [update project using git] ************************************************ fatal: [localhost]: FAILED! => {"changed": false, "cmd": ["/usr/bin/git", "fetch", "--tags", "origin"], "msg": "Failed to download remote objects and refs: fatal: unable to access 'https://bitbucket.org/user/reponame.git/': Could not resolve host: bitbucket.org\n"}
尝试同步GitHub新仓库时也出现类似错误:
TASK [update project using git] ************************************************ fatal: [localhost]: FAILED! => {"changed": false, "cmd": "/usr/bin/git ls-remote https://github.com/ansible/ansible-tower-samples -h refs/heads/HEAD", "msg": "fatal: unable to access 'https://github.com/ansible/ansible-tower-samples/': Could not resolve host: github.com", "rc": 128, "stderr": "fatal: unable to access 'https://github.com/ansible/ansible-tower-samples/': Could not resolve host: github.com\n", "stderr_lines": ["fatal: unable to access 'https://github.com/ansible/ansible-tower-samples/': Could not resolve host: github.com"], "stdout": "", "stdout_lines": []}
安装AWX的服务器可正常ping通上述主机并执行git clone操作。
解决方案
- 检查AWX容器DNS配置:
执行docker exec -it <awx_task_container_name> cat /etc/resolv.conf,对比宿主机的/etc/resolv.conf,确认容器内DNS服务器配置是否和宿主机一致。容器DNS配置异常是这类解析失败的常见原因。 - 手动指定容器DNS服务器:
找到AWX的docker-compose配置文件(通常位于部署目录或/var/lib/awx/下),在awx_task和awx_web服务段添加DNS配置,示例如下:
保存后重启AWX服务:services: awx_task: dns: - 8.8.8.8 - 1.1.1.1 awx_web: dns: - 8.8.8.8 - 1.1.1.1docker-compose down && docker-compose up -d - 验证容器内网络连通性:
进入AWX任务容器,执行ping bitbucket.org和git clone https://bitbucket.org/user/reponame.git,确认域名解析和仓库克隆是否正常。若仍有问题,检查容器网络模式,桥接模式下需确保网络参数配置正确,必要时可切换为宿主机网络模式。 - 检查AWX代理设置:
若宿主机使用代理服务器,确认AWX容器内是否配置了对应代理环境变量。执行docker exec -it <awx_task_container_name> env | grep -i proxy查看,未配置的话可在容器内添加HTTP_PROXY、HTTPS_PROXY环境变量,或在AWX系统设置中配置全局代理。
内容的提问来源于stack exchange,提问作者SctALE
相关产品推荐
相关产品推荐

