diff --git a/changelogs/fragments/5291-fix-nmcli-error-when-setting-unset-mac-address.yaml b/changelogs/fragments/5291-fix-nmcli-error-when-setting-unset-mac-address.yaml new file mode 100644 index 00000000000..b58db74bcfa --- /dev/null +++ b/changelogs/fragments/5291-fix-nmcli-error-when-setting-unset-mac-address.yaml @@ -0,0 +1,2 @@ +bugfixes: + - "nmcli - fix error when setting previously unset MAC address, ``gsm.apn`` or ``vpn.data``: current values were being normalized without checking if they might be ``None`` (https://github.com/ansible-collections/community.general/pull/5291)." diff --git a/plugins/modules/net_tools/nmcli.py b/plugins/modules/net_tools/nmcli.py index f5a45b2f5b3..13adc8bbd24 100644 --- a/plugins/modules/net_tools/nmcli.py +++ b/plugins/modules/net_tools/nmcli.py @@ -2099,15 +2099,18 @@ def _compare_conn_params(self, conn_info, options): # 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() + if current_value: + current_value = current_value.upper() if key == 'gsm.apn': # Depending on version nmcli adds double-qoutes to gsm.apn # Need to strip them in order to compare both - current_value = current_value.strip('"') + if current_value: + current_value = current_value.strip('"') if key == self.mtu_setting and self.mtu is None: self.mtu = 0 if key == 'vpn.data': - current_value = sorted(re.sub(r'\s*=\s*', '=', part.strip(), count=1) for part in current_value.split(',')) + if current_value: + current_value = sorted(re.sub(r'\s*=\s*', '=', part.strip(), count=1) for part in current_value.split(',')) value = sorted(part.strip() for part in value.split(',')) else: # parameter does not exist