Ansible Playbook执行get_url报错:域名解析失败求助
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.comornslookup repo.example.com. If either command fails to return the IPxx.2xx.xx4.40, your system has no idea where to find this domain. - Quick fixes:
- Add a manual entry to
/etc/hostson the executing node:xx.2xx.xx4.40 repo.example.com - Ensure your network’s DNS server has a valid record mapping
repo.example.comto the correct IP.
- Add a manual entry to
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(orsystemctl restart apache2depending 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

