Skip to content
Permalink
Browse files
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
  • Loading branch information
rmuir committed May 23, 2022
1 parent 400475a commit 0f882d010fda19c9bc591a3eb0b6ded6249886c3
Showing 2 changed files with 5 additions and 3 deletions.
@@ -0,0 +1,2 @@
bugfixes:
- facts - fix IP address discovery for specific interface names (https://github.com/ansible/ansible/issues/77792).
@@ -260,19 +260,19 @@ def parse_ip_output(output, secondary=False):

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)

0 comments on commit 0f882d0

Please sign in to comment.