AKS
AKS

Reputation: 17336

ansible - how to pass local DNS server while running ansible-playbook to resolve hostname

I'm using ansible (ansible 1.9.0.1).

I'm running ansible-playbook to perform some operations on a target / remote machine using it's hostname.

My inventory file has an entry for a hostname i.e. appserver01.newdomainname.com

When I run ansible-playbook to just do a simple (hello world example), it doesn't resolve the hostname. If in the inventory file, I have the x.x.x.x IP, then it works!!!!

So, it seems like the nameserver or search in my source machine's /etc/resolv.conf is not resolving the remote hostname using it's fully qualified domain name i.e. appserver01.newdomainname.com

Is there any way I can call ansible-playbook and pass the new/local DNS server so that ansible can resolve the hostname (in the inventory file) from that DNS first (instead of reading / resolving it from the /etc/resolv.conf).

PS: I can't add this new/local DNS nameserver xx.xx.yy.zz to /etc/resolv.conf.

Upvotes: 4

Views: 6223

Answers (1)

ajschmidt
ajschmidt

Reputation: 81

One way you could work around this would be to use the attribute ansible_ssh_host in your inventory file. This is not the same as connecting to your local DNS, but its kind of like transporting the DNS records with your inventory. This way you can still refer to your servers by their hostnames and you don't have to put anything in your servers hosts file. So it would look like this:

[myservers] appserver01.newdomainname.com ansible_ssh_host=x.x.x.x

You could even move these mappings out to a host_vars file and keep a different list of IPs for each of your deployment environments.

Upvotes: 4

Related Questions