Hello,
we would like to manage the /etc/resolv.conf on our RHEL 7 hosts with ansible. But currently the file is generated by NetworkManager.
[root@rhel-t2 ~]# cat /etc/resolv.conf
# Generated by NetworkManager
search sub.exampelcom example.com
nameserver <ip address 1>
nameserver <ip address 2>
My guess is that the NetworkManager generates this file because I use the DNS1
and DNS2
directives in the ifcfg-file and no PEERDNS=no
(see How to make persistent changes to the /etc/resolv.conf?).
What would be the best way to get /etc/resolv.conf under the control of ansible? My first thought was to simply stop using the DNS1
and DNS2
directives in the ifcfg-file and to disable the NetworkManager.service. Without the NetworkManager running I should be able to deploy the /etc/resolv.conf from an ansible template.
What do you think about it? Do you have any other ideas on how to do this?
Best regards,
Joerg
22 mars 2017 11:23 “Jörg Kastning” <joerg.kastning@gmail.com> a écrit:
Hello,
we would like to manage the /etc/resolv.conf on our RHEL 7 hosts with ansible. But currently the file is generated by NetworkManager.
[root@rhel-t2 ~]# cat /etc/resolv.conf # Generated by NetworkManager search sub.exampelcom example.com nameserver <ip address 1> nameserver <ip address 2>
My guess is that the NetworkManager generates this file because I use the DNS1
and DNS2
directives in the ifcfg-file and no PEERDNS=no
(see How to make persistent changes to the /etc/resolv.conf?).
What would be the best way to get /etc/resolv.conf under the control of ansible? My first thought was to simply stop using the DNS1
and DNS2
directives in the ifcfg-file and to disable the NetworkManager.service. Without the NetworkManager running I should be able to deploy the /etc/resolv.conf from an ansible template.
What do you think about it? Do you have any other ideas on how to do this?
Best regards,
Joerg
Hi,
If you want to manage /etc/resolv.conf with ansible like in old version :
You need to had dns=none in this file (hint : use ini module)
/etc/NetworkManager/NetworkManager.conf
[main]
plugins=ifcfg-rh
dns=none
and after you should use a template with some variable with defautls, so you can put more than one domain for the search and more than one DNS server
If not, you should probably use the nmcli module
Regards,
JYL
Hi,
I would like to thank you for your hint. We are going to set the option “dns=none” in NetworkManager.conf with the ansible ‘lineinfile’ module and then deploy the /etc/resolv.conf with the template module.
Thanks,
Joerg
Hello there,
I would like to post a short update to this thread in case someone is going to do the same with the same questions in mind.
Using the module lineinfile I could not guarantee that the option “dns=none” is set in the correct section of /etc/NetworkManager/NetworkManager.conf. While the NetworkManger.conf is an INI like file I’m using the ini_file module instead, now.
Greetz,
Joerg