-1

I have to apply the following configuration on several hosts via Ansible:

nmcli device modify "device_name" ens192 ipv6.method "disabled"

I wanted to use the nmcli module instead of a command as it is cleaner. But from what I found on the documentation and forums the nmcli module manage only connections.

Apart from recovering all connections associated to an interface and modifying each one using Ansible nmcli module I could not find a way to do it. This solution beeing, in my opinion, uglier than using command module I will stick with command.

Any informed comment or suggestion would be appreciated.

For the sake of precision the current code used to disable ipv6 if networkmanager is used:

- name: get service facts
  service_facts:

- name: Disable ipv6 with network manager
  become: yes
  command: "/bin/nmcli device modify {{ ansible_default_ipv4.interface }} ipv6.method 'disabled'"
  when: ansible_facts.services["NetworkManager.service"] is defined
  changed_when: false
U880D
  • 8,601
  • 6
  • 24
  • 40
  • I have never used the module but [its documentation](https://docs.ansible.com/ansible/latest/collections/community/general/nmcli_module.html) gives a quite different overview in terms of support than what your report in your question. First line of synopsys `Manage the network devices. Create, modify and manage various connection and device type e.g., ethernet, teams, bonds, vlans etc.` – Zeitounator Jul 13 '22 at 13:08

1 Answers1

1

I am not sure if I understand your question fully since there is no example what you have tried, problem description, description of your system, used versions, confguration or error messages.


Regarding

I wanted to use the nmcli module instead of a command as it is cleaner

and according the documentation of the module nmcli there is a parameter ifname

The interface to bind the connection to. The connection will only be applicable to this interface name. A special value of '*' can be used for interface-independent connections. The ifname argument is mandatory for all connection types except bond, team, bridge, vlan and vpn. This parameter defaults to conn_name when left unset for all connection types except vpn that removes it.

So looking at the CLI output of nmcli device show

GENERAL.DEVICE:                         eth0
GENERAL.TYPE:                           ethernet
GENERAL.HWADDR:                         AB:CD:EF:01:02:03
GENERAL.MTU:                            1500
GENERAL.STATE:                          100 (connected)
GENERAL.CONNECTION:                     eth0
...

and since conn_name obviously points to GENERAL.CONNECTION, wouldn't that parameter ifname for GENERAL.DEVICE not be that one which you are looking for?

The Examples are showing also the usage of ifname together with conn_name.

Furthermore ipv6.method disabled isn't available in example in RHEL 7, but as of 8.

- name: Make sure IPv6 is disabled
  shell:
    cmd: nmcli conn mod eth0 ipv6.method disabled
  when: ansible_distribution == 'RedHat' and ansible_distribution_major_version == '8'
U880D
  • 8,601
  • 6
  • 24
  • 40