From 0f882d010fda19c9bc591a3eb0b6ded6249886c3 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Mon, 23 May 2022 02:58:31 -0400 Subject: [PATCH] Supply 'dev' keyword for linux network facts discovery (#77793) This avoids incorrect results when the device name conflicts with another 'ip' keyword. For example, if the device name is 'primary'. Closes #77792 --- .../77792-fix-facts-discovery-specific-interface-names.yml | 2 ++ lib/ansible/module_utils/facts/network/linux.py | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/77792-fix-facts-discovery-specific-interface-names.yml diff --git a/changelogs/fragments/77792-fix-facts-discovery-specific-interface-names.yml b/changelogs/fragments/77792-fix-facts-discovery-specific-interface-names.yml new file mode 100644 index 00000000000..7616e37c1f2 --- /dev/null +++ b/changelogs/fragments/77792-fix-facts-discovery-specific-interface-names.yml @@ -0,0 +1,2 @@ +bugfixes: + - facts - fix IP address discovery for specific interface names (https://github.com/ansible/ansible/issues/77792). diff --git a/lib/ansible/module_utils/facts/network/linux.py b/lib/ansible/module_utils/facts/network/linux.py index aae4a0f3a0f..b7ae97656ba 100644 --- a/lib/ansible/module_utils/facts/network/linux.py +++ b/lib/ansible/module_utils/facts/network/linux.py @@ -260,19 +260,19 @@ class LinuxNetwork(Network): ip_path = self.module.get_bin_path("ip") - args = [ip_path, 'addr', 'show', 'primary', device] + args = [ip_path, 'addr', 'show', 'primary', 'dev', device] rc, primary_data, stderr = self.module.run_command(args, errors='surrogate_then_replace') if rc == 0: parse_ip_output(primary_data) else: # possibly busybox, fallback to running without the "primary" arg # https://github.com/ansible/ansible/issues/50871 - args = [ip_path, 'addr', 'show', device] + args = [ip_path, 'addr', 'show', 'dev', device] rc, data, stderr = self.module.run_command(args, errors='surrogate_then_replace') if rc == 0: parse_ip_output(data) - args = [ip_path, 'addr', 'show', 'secondary', device] + args = [ip_path, 'addr', 'show', 'secondary', 'dev', device] rc, secondary_data, stderr = self.module.run_command(args, errors='surrogate_then_replace') if rc == 0: parse_ip_output(secondary_data, secondary=True)