Skip to content

Idempotence in the nmcli module with the 'route_metric4' parameter #4998

@VolodymyrSerh

Description

@VolodymyrSerh

Summary

I figured out some Idempotence in the nmcli module with the 'route_metric4' parameter.
This issue is actual for both Ansible versions, 5.7 and 6.0.
By default, the route metric value is '-1'. You can verify this if you run the 'nmcli conn sh eth0' command, for example.

ipv4.route-metric: -1
ipv4.route-table: 0 (unspec)

If we have this value in our host vars and no one other network parameter changes, the playbook with nmcli task nothing change on the target system.
But only if we change any other network parameter 'route4', 'ipv6.method', doesn't matter, the 'route_metric4' parameter also will change from "-1" to -1.

  • "ipv4.route-metric": "-1",
  • "ipv4.route-metric": -1,

Of course, nothing has been changed on the target system finally, and 'nmcli conn sh' is showing the '-1' value as was before the playbook run.
It looks no so good.

Issue Type

Bug Report

Component Name

nmcli module

Ansible Version

$ ansible --version
ansible [core 2.12.7]
  config file = /home/user/git/ansible_configs/ansible.cfg
  configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/user/.local/lib/python3.8/site-packages/ansible
  ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/user/.local/bin/ansible
  python version = 3.8.10 (default, Jun 22 2022, 20:18:18) [GCC 9.4.0]
  jinja version = 3.0.3
  libyaml = True

Community.general Version

$ ansible-galaxy collection list community.general
Collection        Version
----------------- -------
community.general 4.8.0  

Configuration

$ ansible-config dump --only-changed
DEFAULT_STRATEGY(/home/user/git/ansible_configs/ansible.cfg) = mitogen_linear
DEFAULT_STRATEGY_PLUGIN_PATH(/home/user/git/ansible_configs/ansible.cfg) = ['/home/user/git/ansible_configs/plugins/strategy/mitogen-0.3.2/ansible_mitogen/plugins/strategy']
HOST_KEY_CHECKING(/home/user/git/ansible_configs/ansible.cfg) = False
MAX_FILE_SIZE_FOR_DIFF(/home/user/git/ansible_configs/ansible.cfg) = 2097152
PERSISTENT_CONNECT_TIMEOUT(/home/user/git/ansible_configs/ansible.cfg) = 30

OS / Environment

Ubuntu 20.04

Steps to Reproduce

- name: Configure network interfaces via nmcli
  community.general.nmcli:
    conn_name: '{{ item.device }}'
    ifname: '{{ item.device }}'
    type: ethernet
    ip4: '{{ item.ip4 }}'
    gw4: '{{ item.gw }}'
    routes4: '{{ item.routes }}'
    method6: ignore
    route_metric4: '{{ item.metric }}'
    state: present
  tags:
    - 'network'
  with_items: '{{ facts_ifaces }}'

The route_metric4 by default have value '-1'
{
"msg": [
{
"device": "eth0",
"gw": null,
"ip4": "xx.xx.xx.xx/24",
"metric": -1,
"routes": []
}
]
}

Expected Results

I expected the route metric didn't changed if in host_vars and in real system it value were similar, '-1'
But when any other parameter will change for this interface the 'route_metric4' will change too.

Actual Results

--- before                                                                                                                                                                                                                      
+++ after                                                                                                                                                                                                                       
@@ -10,11 +10,12 @@                                                                                                                                                                                                             
     "ipv4.may-fail": "yes",                                                                                                                                                                                                    
     "ipv4.method": "manual",                                                                                                                                                                                                   
     "ipv4.never-default": "no",                                                                                                                                                                                                
-    "ipv4.route-metric": "-1",                                                                                                                                                                                                 
+    "ipv4.route-metric": -1,                                                                                                                                                                                                   
     "ipv4.routes": [                                                                                                                                                                                                                                                                                                                                                                                                     
     ],                                                                                                                                                                                                                         
     "ipv6.ignore-auto-dns": "no",                                                                                                                                                                                              
     "ipv6.ignore-auto-routes": "no",                                                                                                                                                                                           
-    "ipv6.method": "disabled"                                                                                                                                                                                                  
+    "ipv6.method": "ignore"                                                                                                                                                                                                    
 }                              

Code of Conduct

  • I agree to follow the Ansible Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions