4
votes

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.

1
I don't think this is possible, because I don't see an option in ssh for this. The only thing I can think of, besides actually defining the IP's in the Ansible inventory or .ssh/config, is an ssh tunnel (ProxyCommand). If you delegate all tasks through a host from where the target hosts are resolvable the hostnames don't need to be resolvable locally.udondan
When you just ssh appserver01.newdomainname.com from your master, does that work?Mxx
@Mxx no. Because /etc/resolv.conf doesn't have nameserver entry to resolve the newdomain.com. We also don't want to update /etc/hosts file on every server (where we'll be running ansible-playbook) and also we constantly create new domains each day (any body in the DEV team can create mynewdomain.com or myname.com domains while creating a VM/Vapp in VCloud). It'd really help if I can have a option to ansible / ansible-playbook to pass an extra DNS server so that if production/server's doesn't resolve your domain, then ansible will use the DNS server we passed at command line to resolve it.AKS

1 Answers

3
votes

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.