diff --git a/changelogs/fragments/50871-facts-ip-addr-busybox.yaml b/changelogs/fragments/50871-facts-ip-addr-busybox.yaml new file mode 100644 index 0000000000..710d37a6a7 --- /dev/null +++ b/changelogs/fragments/50871-facts-ip-addr-busybox.yaml @@ -0,0 +1,2 @@ +bugfixes: + - Detect IP addresses on a system with busybox properly (https://github.com/ansible/ansible/issues/50871) diff --git a/lib/ansible/module_utils/facts/network/linux.py b/lib/ansible/module_utils/facts/network/linux.py index 074cc6b935..88981b8ef0 100644 --- a/lib/ansible/module_utils/facts/network/linux.py +++ b/lib/ansible/module_utils/facts/network/linux.py @@ -256,12 +256,20 @@ class LinuxNetwork(Network): args = [ip_path, 'addr', 'show', 'primary', 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] + 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] rc, secondary_data, stderr = self.module.run_command(args, errors='surrogate_then_replace') - - parse_ip_output(primary_data) - parse_ip_output(secondary_data, secondary=True) + if rc == 0: + parse_ip_output(secondary_data, secondary=True) interfaces[device].update(self.get_ethtool_data(device))