From 682c6fc967ffde3c11151972f31083423e3d008c Mon Sep 17 00:00:00 2001 From: Jonathan Kamens Date: Sat, 25 Feb 2023 05:00:43 -0500 Subject: [PATCH] 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 --- changelogs/fragments/6048-nmcli-addres-order.yml | 2 ++ plugins/modules/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/nmcli.py b/plugins/modules/nmcli.py index 999e06cc12..61b0325fe9 100644 --- a/plugins/modules/nmcli.py +++ b/plugins/modules/nmcli.py @@ -2144,8 +2144,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: