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?
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 …