# How to change dns resolver used by playbook?

**URL:** <https://forum.ansible.com/t/how-to-change-dns-resolver-used-by-playbook/8193>\
**Category:** Get Help\
**Tags:** playbook\
**Created:** [August 31, 2024, 8:07am UTC](https://forum.ansible.com/t/how-to-change-dns-resolver-used-by-playbook/8193 "2024-08-31T08:07:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![numpty-boy](https://avatars.discourse-cdn.com/v4/letter/n/6f9a4e/32.png) [@numpty-boy](https://forum.ansible.com/u/numpty-boy)\
**Post date:** [August 31, 2024, 8:07am UTC](https://forum.ansible.com/t/how-to-change-dns-resolver-used-by-playbook/8193/1 "2024-08-31T08:07:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jpmens](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jpmens/32/5543_2.png) [@jpmens](https://forum.ansible.com/u/jpmens)\
**Post date:** [August 31, 2024, 11:27am UTC](https://forum.ansible.com/t/how-to-change-dns-resolver-used-by-playbook/8193/2 "2024-08-31T11:27:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jpmens](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jpmens/32/5543_2.png) [@jpmens](https://forum.ansible.com/u/jpmens)\
**Post date:** [August 31, 2024, 11:31am UTC](https://forum.ansible.com/t/how-to-change-dns-resolver-used-by-playbook/8193/3 "2024-08-31T11:31:01Z")

</div>

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 …

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [August 31, 2024, 5:35pm UTC](https://forum.ansible.com/t/how-to-change-dns-resolver-used-by-playbook/8193/4 "2024-08-31T17:35:09Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![numpty-boy](https://avatars.discourse-cdn.com/v4/letter/n/6f9a4e/32.png) [@numpty-boy](https://forum.ansible.com/u/numpty-boy)\
**Post date:** [September 9, 2024, 7:10am UTC](https://forum.ansible.com/t/how-to-change-dns-resolver-used-by-playbook/8193/5 "2024-09-09T07:10:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![numpty-boy](https://avatars.discourse-cdn.com/v4/letter/n/6f9a4e/32.png) [@numpty-boy](https://forum.ansible.com/u/numpty-boy)\
**Post date:** [September 9, 2024, 7:13am UTC](https://forum.ansible.com/t/how-to-change-dns-resolver-used-by-playbook/8193/6 "2024-09-09T07:13:38Z")

</div>

Thanks for the suggestion. DNS is fine.

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