From d25b6e76812184c735680b6b0244c2a74ad2c500 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Wed, 28 Sep 2022 23:19:17 +0200 Subject: [PATCH] nmcli: fix error when setting previously unset mac address (#5291) (#5318) * fix #5290 * add changelog fragment * remove unnecessary braces * Update changelogs/fragments/5291-fix-nmcli-error-when-setting-unset-mac-address.yaml Co-authored-by: Felix Fontein Co-authored-by: Felix Fontein (cherry picked from commit ec9e10d6d1dc83cb47bf30fb7fd14af65eccc6a9) Co-authored-by: Giorgio Gallo --- ...1-fix-nmcli-error-when-setting-unset-mac-address.yaml | 2 ++ plugins/modules/net_tools/nmcli.py | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/5291-fix-nmcli-error-when-setting-unset-mac-address.yaml 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 0000000000..b58db74bcf --- /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 f5a45b2f5b..13adc8bbd2 100644 --- a/plugins/modules/net_tools/nmcli.py +++ b/plugins/modules/net_tools/nmcli.py @@ -2099,15 +2099,18 @@ class Nmcli(object): # 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