From 1f5703d0af1ead17b4ebc65ae455afdf565738db Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Sat, 25 Feb 2023 11:29:41 +0100 Subject: [PATCH] [PR #6048/682c6fc9 backport][stable-5] nmcli: Treat order as significant when comparing address lists (#6081) nmcli: Treat order as significant when comparing address lists (#6048) * nmcli: Treat order as significant when comparing address lists Don't sort the old and new values for ipv4.addresses and ipv6.addresses before comparing them, because order matters in these parameters: the first address specified is the default source address for outbound connections. * Changelog fragment for #6048 * Update changelogs/fragments/6048-nmcli-addres-order.yml Co-authored-by: Felix Fontein --------- Co-authored-by: Felix Fontein (cherry picked from commit 682c6fc967ffde3c11151972f31083423e3d008c) Co-authored-by: Jonathan Kamens --- changelogs/fragments/6048-nmcli-addres-order.yml | 2 ++ plugins/modules/net_tools/nmcli.py | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/6048-nmcli-addres-order.yml diff --git a/changelogs/fragments/6048-nmcli-addres-order.yml b/changelogs/fragments/6048-nmcli-addres-order.yml new file mode 100644 index 0000000000..4de15cf084 --- /dev/null +++ b/changelogs/fragments/6048-nmcli-addres-order.yml @@ -0,0 +1,2 @@ +bugfixes: + - nmcli - order is significant for lists of addresses (https://github.com/ansible-collections/community.general/pull/6048). diff --git a/plugins/modules/net_tools/nmcli.py b/plugins/modules/net_tools/nmcli.py index 51523b3244..71d0c492dd 100644 --- a/plugins/modules/net_tools/nmcli.py +++ b/plugins/modules/net_tools/nmcli.py @@ -2137,8 +2137,12 @@ class Nmcli(object): if isinstance(current_value, list) and isinstance(value, list): # compare values between two lists - if sorted(current_value) != sorted(value): - changed = True + if key in ('ipv4.addresses', 'ipv6.addresses'): + # The order of IP addresses matters because the first one + # is the default source address for outbound connections. + changed |= current_value != value + else: + changed |= sorted(current_value) != sorted(value) elif all([key == self.mtu_setting, self.type == 'dummy', current_value is None, value == 'auto', self.mtu is None]): value = None else: