Nmcli changes not persistent in rhel 8.6

I have a DHCP Rhel 8.6 in Azure system that runs cloud-init at each boot. I want to change the obtained DNS servers at each boot for a specific DNS. But I want to do it in ansible. My question is why the following ansible does not persist after each reboot?

- hosts: localhost
  become: yes
      - name: setting DNS resolver config, remove default DNS as it is not my DC ip address
          conn_name='System eth0'
      - name: restart NetworkManager service
        service: name=NetworkManager state=restarted

After each reboot, my changes are reverted and I am back to have in /etc/resolv.conf the DHCP obtained DNS entries.

$ ansible --version
ansible [core 2.12.2]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/sysadm/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.8/site-packages/ansible
  ansible collection location = /home/sysadm/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.8.12 (default, Jun 27 2023, 13:28:18) [GCC 8.5.0 20210514 (Red Hat 8.5.0-10)]
  jinja version = 2.10.3
  libyaml = True

Thanks in advance for your comments.


Hello @ErickPH,

Check this link out:

In Section 2 - Configuring an Ethernet Connection there is this notice:

Could this be the root of your issue?



Hi @ErickPH , welcome to the Ansible community forum!

Adding to the great catch by @jbericat , you might also want to check out the Ansible RHEL System Roles (or upstream Linux System Roles for those without RHEL subscriptions) for configuration management of all the RHEL subsystems.

Have a look at the specific system role for networking for example:


That’s a good one too @Leo !


Hi @ErickPH! It looks like the post might be solved - could you check to see if the response by @jbericat or @leo worked for you?

If so, it would be super helpful if you could click the :heavy_check_mark: on their post to accept the solution - it recognises the input of others, helps our volunteers find new issues to answer, and keeps the forum nice and tidy.

(this is template reply, do feel free to reply if I’ve misunderstood the situation!)

1 Like