From 11fb0a5d6a6c469cbfdd89922bb2d7598898a549 Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Wed, 23 Jan 2019 22:24:29 +0100 Subject: [PATCH] facts: detect IP addresses on busybox properly (#51131) * facts: detect IP addresses on busybox properly Fixes #50871 * Check rc before parsing data * Ooops --- .../fragments/50871-facts-ip-addr-busybox.yaml | 2 ++ lib/ansible/module_utils/facts/network/linux.py | 14 +++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/50871-facts-ip-addr-busybox.yaml 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))