How to change dns resolver used by playbook?

Hi Team

I have a playbook i run in several different situations, in each case with a different inventory file.

The inventory files use FQDNs.

In each case i have to edit /etc/resolv.conf to change the dns resolver before running it.

I know i could hardcode IP addresses within inventory files or set up a local nameserver with a bunch of forwarder records, but before i do something like that, a question …

Is there a way to change the DNS resolver on a per playbook basis, or from the commandline?

Thanks ChIP

There is no portable way of doing so on Unix/Linux, and while you might be able to invent a method which uses LD_LIBRARY_PATH to circumvent the current resolver library and thus its configuration, I wouldn’t go down that route.

What I would do in this case, and I know you said you’d prefer to avoid it, is use ansible_host= in inventory or group_vars/host_vars, etc.

Alternatively you might be able to set up your own resolver which permits you to reconfigure hosts on the fly, but it’s a lot of work and won’t reduce the number of moving bits.

Your playbooks and inventory contains FQDN, you write. Would you be able to generate the inventory with the specific IP addresses on the fly? Be it either a statically created inventory or a dynamic inventory? Just a thought …

This sounds like DNS is not set up right on your Ansible controller.

What specifically are you changing in /etc/resolv.conf that makes it work?

Thanks for your time. I guess ill have to resort to something like yhat … all totally doable, but just wanted to make sure i wasnnt missing anything.

Thanks for the suggestion. DNS is fine.

Im changing ‘nameserver’ clause in resolv.conf to point to the ‘correct’ resolver for each client.