diff --git a/changelogs/fragments/2416-nmcli_compare_mac_addresses_case_insensitively.yml b/changelogs/fragments/2416-nmcli_compare_mac_addresses_case_insensitively.yml new file mode 100644 index 0000000000..6694638964 --- /dev/null +++ b/changelogs/fragments/2416-nmcli_compare_mac_addresses_case_insensitively.yml @@ -0,0 +1,2 @@ +bugfixes: + - nmcli - compare MAC addresses case insensitively to fix idempotency issue (https://github.com/ansible-collections/community.general/issues/2409). diff --git a/plugins/modules/net_tools/nmcli.py b/plugins/modules/net_tools/nmcli.py index 02fbbd038b..e2ed4ad572 100644 --- a/plugins/modules/net_tools/nmcli.py +++ b/plugins/modules/net_tools/nmcli.py @@ -1042,7 +1042,6 @@ class Nmcli(object): 'con-name': 'connection.id', 'autoconnect': 'connection.autoconnect', 'ifname': 'connection.interface-name', - 'mac': self.mac_setting, 'master': 'connection.master', 'slave-type': 'connection.slave-type', 'zone': 'connection.zone', @@ -1066,6 +1065,11 @@ class Nmcli(object): current_value = [re.sub(r'^{\s*ip\s*=\s*([^, ]+),\s*nh\s*=\s*([^} ]+),\s*mt\s*=\s*([^} ]+)\s*}', r'\1 \2 \3', route) for route in current_value] current_value = [re.sub(r'^{\s*ip\s*=\s*([^, ]+),\s*nh\s*=\s*([^} ]+)\s*}', r'\1 \2', route) for route in current_value] + if key == self.mac_setting: + # MAC addresses are case insensitive, nmcli always reports them in uppercase + value = value.upper() + # ensure current_value is also converted to uppercase in case nmcli changes behaviour + current_value = current_value.upper() elif key in param_alias: real_key = param_alias[key] if real_key in conn_info: diff --git a/tests/unit/plugins/modules/net_tools/test_nmcli.py b/tests/unit/plugins/modules/net_tools/test_nmcli.py index a05c8ccbf8..dceb5e5f3f 100644 --- a/tests/unit/plugins/modules/net_tools/test_nmcli.py +++ b/tests/unit/plugins/modules/net_tools/test_nmcli.py @@ -184,6 +184,7 @@ TESTCASE_BRIDGE = [ 'ifname': 'br0_non_existant', 'ip4': '10.10.10.10/24', 'gw4': '10.10.10.1', + 'mac': '52:54:00:ab:cd:ef', 'maxage': 100, 'stp': True, 'state': 'present', @@ -200,6 +201,7 @@ ipv4.addresses: 10.10.10.10/24 ipv4.gateway: 10.10.10.1 ipv4.never-default: no ipv6.method: auto +bridge.mac-address: 52:54:00:AB:CD:EF bridge.stp: yes bridge.max-age: 100 bridge.ageing-time: 300