Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apply nmcli configuration #3752

Closed
1 task done
avbg opened this issue Nov 18, 2021 · 6 comments · Fixed by #8897
Closed
1 task done

apply nmcli configuration #3752

avbg opened this issue Nov 18, 2021 · 6 comments · Fixed by #8897
Labels
feature This issue/PR relates to a feature request module module net_tools plugins plugin (any type)

Comments

@avbg
Copy link

avbg commented Nov 18, 2021

Summary

Problem: how to apply the configuration on the host after launching the "nmcli" module?
Now I do it through the nmcli up handler. maybe there is another option that I don't know about?

I expected that with the "present" state, they would be applied, since this is the internal mechanism of the NetworkManager.
Perhaps a new state should be added for this?

ansible --version
ansible [core 2.11.1] 
  config file = /srv/infra/itpark/ansible/ansible.cfg
  configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/user/pythonEnvs/ansible/lib/python3.9/site-packages/ansible
  ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/user/pythonEnvs/ansible/bin/ansible
  python version = 3.9.7 (default, Oct 10 2021, 15:13:22) [GCC 11.1.0]
  jinja version = 3.0.1
  libyaml = True

Issue Type

Feature Idea

Component Name

nmcli

Additional Information

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@ansibullbot
Copy link
Collaborator

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added feature This issue/PR relates to a feature request module module net_tools plugins plugin (any type) labels Nov 18, 2021
@Ajpantuso
Copy link
Collaborator

NetworkManager doesn't apply changes to an active connection until the configuration is reloaded. In Ansible you would typically notify a handler to either restart NetworkManager or run nmcli con reload. If we added an option to do this it probably wouldn't be a new state, but something like reload which when set to True would toggle active connections with con down and then con up.

@avbg
Copy link
Author

avbg commented Nov 18, 2021

It's not so important through an option or through a state. it is much more convenient when inside the module, and not through the handler.

@ansibullbot
Copy link
Collaborator

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

@rptaylor
Copy link

rptaylor commented Sep 11, 2023

Different operations can require different commands to apply them. Usually restarting NetworkManager is not the recommended/desired thing to do except for some special cases (0 1 2)

It is not necessary or recommended to restart NetworkManager to reload interface configuration files.

Note that a restart of the NetworkManager service is usually not required, for example when doing changes to the
networking configuration. This is one of the exceptions.

Even nmcli con reload may not work in some cases:

Note: This action only makes NetworkManager aware of any changes to configuration,
it does not apply changes to an already-up connection.

Personally I have found it pretty confusing to determine which operation is needed to apply what kind of change when using NetworkManager, which in turn makes it difficult as a user to try to make the nmcli module apply changes, even if I had to write a handler for every invocation of the module which would be very cumbersome.

Often nmcli dev reapply devicename is the right thing to do, but not always, e.g.

# nmcli dev reapply bond0
Error: Reapplying connection to device 'bond0' (/org/freedesktop/NetworkManager/Devices/14) failed: Can't reapply 'lacp_rate' bond option

so in that case nmcli down/up bond0 is required. That makes a total of 4 (at least) different possible commands that may be required to apply a nmcli change!

Anyway even just considering the one case of nmcli dev reapply devicename, making a handler to reapply the device that has been changed would require a variable (apparently using variables in a handler requires include_vars ???) and more complexity in crafting tasks properly compared to the module just doing a reapply while it is modifying a device.

Preferably the ansible module would "do the right thing" to apply whatever type of change is made with some option apply or reload (default True).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This issue/PR relates to a feature request module module net_tools plugins plugin (any type)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants