Bootstrap FreeKB - Ansible - Modify Network Manager using the nmcli module
Ansible - Modify Network Manager using the nmcli module

Updated:   |  Ansible articles

The community.general.nmcli module can be used to add, modify or remove Network Manager settings. This is similar to the nmcli connection modify command. In this example, the eth0 interface is modified to include IPv4 addresses.

Often, you will want to use the systemd module to restart the network systemd service after making the change to Network Manager.

---
- hosts: all
  tasks:
  - name: add IPV4 addresses to eth0 interface
    community.general.nmcli:
      conn_name: eth0
      type: ethernet
      state: present
      dns4:
      - 10.5.17.5
      - 10.5.17.6

  - name: restart network service
    systemd:
      name: network
      state: restarted
...

 

And in this example, the eth0 interface is modified to include IPv4 DNS search domains.

---
- hosts: all
  tasks:
  - name: add IPV4 DNS search domains to eth0 interface
    community.general.nmcli:
      conn_name: eth0
      type: ethernet
      state: present
      dns4_search:
      - example.com
      - foo.example.com
      - bar.example.com

  - name: restart network service
    systemd:
      name: network
      state: restarted
...

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter be78b5 in the box below so that we can be sure you are a human.