I'm working on an ansible playbook to set the dns server addresses in my Ubuntu Bionic 18.04.2 server.

I don't want to use resolv.conf cause I learned it's deprecated in the new Ubuntu.

My question is: Is there an easy way to set the nameservers with netplan or ip link set utility without changing files (cause is not that simple with ansible)?


You can inject nameservers at runtime using the resolvectl tool. However, note that these settings will not persist across reboots of the target system. It is probably better to emit your config to a separate file under /etc/netplan/ that you manage exclusively with ansible, and which lists only the dns server settings that you wish to provide, and then call netplan apply, so that the setting persists across reboot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.