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
pull/77876/head
Robert Muir 4 years ago committed by GitHub
parent 400475acc0
commit 0f882d010f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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 @@ 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)

Loading…
Cancel
Save