# Nmcli ansible module

**URL:** <https://forums.rockylinux.org/t/nmcli-ansible-module/4069>\
**Category:** Rocky Linux Help & Support\
**Created:** [September 15, 2021, 9:25am UTC](https://forums.rockylinux.org/t/nmcli-ansible-module/4069 "2021-09-15T09:25:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sky007](https://avatars.discourse-cdn.com/v4/letter/s/e5b9ba/32.png) [@Sky007](https://forums.rockylinux.org/u/Sky007)\
**Post date:** [September 15, 2021, 9:25am UTC](https://forums.rockylinux.org/t/nmcli-ansible-module/4069/1 "2021-09-15T09:25:23Z")

</div>

Hi,  
Anyone used nmcli ansible module to configure Ethernet Interface in a Virtual Machine. Simple task to enable Ethernet interface is not getting interface to Active. We manually need to UP the interface to update the configurations like IPv4 address, GW etc.

Disabling seems working fine.

---

<div class="post-metadata">

**Author:** ![jlehtone](https://avatars.discourse-cdn.com/v4/letter/j/e9a140/32.png) [@jlehtone](https://forums.rockylinux.org/u/jlehtone)\
**Post date:** [September 15, 2021, 9:42am UTC](https://forums.rockylinux.org/t/nmcli-ansible-module/4069/2 "2021-09-15T09:42:46Z")

</div>

autoconnect=yes? Or NM restart in handler?

Tell the truth, I haven’t dared to config network with ansible yet. Feels like sawing a branch while sitting on it.

---

<div class="post-metadata">

**Author:** ![Sky007](https://avatars.discourse-cdn.com/v4/letter/s/e5b9ba/32.png) [@Sky007](https://forums.rockylinux.org/u/Sky007)\
**Post date:** [September 15, 2021, 1:41pm UTC](https://forums.rockylinux.org/t/nmcli-ansible-module/4069/3 "2021-09-15T13:41:28Z")

</div>

Tried with “autoconnect”: true and above scenario noticed.

Also trying to see how nmcli ansible modules can be used policy routing to Rocky VM’s.  
Eg: like use of routing\_rules4

We could able to update rules for single entries as,  
routing\_rules4: “priority 0 from {{ item.ip4 | ipaddr(‘address’) }} lookup {{ item.route\_table }}”

But when we tried add one one entry it’s not working.

Anyone tried adding multiple rules similar to this

---

<div class="post-metadata">

**Author:** ![jlehtone](https://avatars.discourse-cdn.com/v4/letter/j/e9a140/32.png) [@jlehtone](https://forums.rockylinux.org/u/jlehtone)\
**Post date:** [September 15, 2021, 2:33pm UTC](https://forums.rockylinux.org/t/nmcli-ansible-module/4069/4 "2021-09-15T14:33:34Z")

</div>

As said, I haven’t used ansible to do network. Not much policy routing either.  
Besides, I use ansible 2.9. routing\_rules4 is not in it.

There is package to enable legacy rule format:

```auto
Name : NetworkManager-dispatcher-routing-rules
Description : This adds a NetworkManager dispatcher file to support networking
             : configurations using "/etc/sysconfig/network-scripts/rule-NAME" files
             : (eg, to do policy-based routing).

```

That obviously works around the lacking “native support” of nmcli.

[Chapter&nbsp;22.&nbsp;Configuring policy-based routing to define alternative routes Red Hat Enterprise Linux 8 | Red Hat Customer Portal](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/configuring_and_managing_networking/configuring-policy-based-routing-to-define-alternative-routes_configuring-and-managing-networking) says:  
“Note that the syntax in the `ipv4.routing-rules` parameter is the same as in an `ip route add` command, except that `ipv4.routing-rules` always requires specifying a priority.”  
which makes no sense as it should invoke equivalent of `ip rule add` (unless ‘rule add’ and ‘route add’ use same syntax).

In `man nm-settings` the `ipv4.routing-rules` is undocumented.

You can create the legacy rules with Ansible.

---

<div class="post-metadata">

**Author:** ![Sky007](https://avatars.discourse-cdn.com/v4/letter/s/e5b9ba/32.png) [@Sky007](https://forums.rockylinux.org/u/Sky007)\
**Post date:** [September 15, 2021, 2:40pm UTC](https://forums.rockylinux.org/t/nmcli-ansible-module/4069/5 "2021-09-15T14:40:39Z")

</div>

Yes. I think for policy based routing as you mentioned using legacy rules could be good at this point of time. For common configurations nmcli works fine.

Thanks for the information

---

<div class="post-metadata">

**Author:** ![brian](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.rockylinux.org/brian/32/5777_2.png) [@brian](https://forums.rockylinux.org/u/brian)\
**Post date:** [August 25, 2023, 4:05am UTC](https://forums.rockylinux.org/t/nmcli-ansible-module/4069/6 "2023-08-25T04:05:20Z")

</div>

Closed on August 25, 2023, 4:05am UTC


