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

Ansible Playbook执行get_url报错:域名解析失败求助

Troubleshooting "Request failed, urlopen error Name or service not known" in Your Ansible Playbook

Let’s break down the most likely causes of this error and walk through how to fix them:

1. DNS Resolution Failure (The Most Common Culprit)

That error message directly tells us the system running your Ansible playbook can’t translate the repo.example.com hostname into an IP address. Here’s how to verify and fix this:

  • On the node where Ansible is executing the download task, run ping repo.example.com or nslookup repo.example.com. If either command fails to return the IP xx.2xx.xx4.40, your system has no idea where to find this domain.
  • Quick fixes:
    • Add a manual entry to /etc/hosts on the executing node: xx.2xx.xx4.40 repo.example.com
    • Ensure your network’s DNS server has a valid record mapping repo.example.com to the correct IP.

2. Incomplete Apache VirtualHost Configuration

Your provided Apache config snippet is missing the full <VirtualHost> block, which might be misconfigured to serve files from /var/www/html/repo.example.com:

  • Make sure your VirtualHost explicitly points to the correct document root for repo.example.com. It should look something like this:
NameVirtualHost xx.2xx.xx4.40:80
<VirtualHost xx.2xx.xx4.40:80>
    DocumentRoot "/var/www/html/repo.example.com"
    ServerName repo.example.com:80

    # Optional but recommended: Secure the directory access
    <Directory "/var/www/html/repo.example.com">
        AllowOverride None
        Require all granted
    </Directory>
</VirtualHost>
  • After updating the config, restart Apache with systemctl restart httpd (or systemctl restart apache2 depending on your distro) to apply changes.

3. Typos in Your Ansible Playbook URL

Double-check the url parameter in your web.yml playbook (you’re probably using the get_url module). A tiny typo like repo.exmaple.com or repos.example.com would trigger the exact same resolution error. Confirm your task looks like this:

- name: Download tar file from repo server
  get_url:
    url: http://repo.example.com/your-target-file.tar
    dest: /path/to/save/the/file.tar

4. Firewall/Network Blocking (Less Likely for This Specific Error)

While your error points to resolution issues, it’s worth confirming node2’s firewall allows incoming traffic on port 80. Run ufw status or firewall-cmd --list-all to verify port 80 is open to the executing node.


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.14 09:06:35