diff --git a/changelogs/fragments/72516-fix-aix-network-facts.yml b/changelogs/fragments/72516-fix-aix-network-facts.yml new file mode 100644 index 00000000000..2efb5972781 --- /dev/null +++ b/changelogs/fragments/72516-fix-aix-network-facts.yml @@ -0,0 +1,2 @@ +bugfixes: + - Fixed issue when `netstat` is either missing or doesn't have execution permissions leading to incorrect command being executed. \ No newline at end of file diff --git a/lib/ansible/module_utils/facts/network/aix.py b/lib/ansible/module_utils/facts/network/aix.py index 46bbb68f670..e9c90c64139 100644 --- a/lib/ansible/module_utils/facts/network/aix.py +++ b/lib/ansible/module_utils/facts/network/aix.py @@ -30,22 +30,23 @@ class AIXNetwork(GenericBsdIfconfigNetwork): platform = 'AIX' def get_default_interfaces(self, route_path): - netstat_path = self.module.get_bin_path('netstat') - - rc, out, err = self.module.run_command([netstat_path, '-nr']) - interface = dict(v4={}, v6={}) - lines = out.splitlines() - for line in lines: - words = line.split() - if len(words) > 1 and words[0] == 'default': - if '.' in words[1]: - interface['v4']['gateway'] = words[1] - interface['v4']['interface'] = words[5] - elif ':' in words[1]: - interface['v6']['gateway'] = words[1] - interface['v6']['interface'] = words[5] + netstat_path = self.module.get_bin_path('netstat') + + if netstat_path: + rc, out, err = self.module.run_command([netstat_path, '-nr']) + + lines = out.splitlines() + for line in lines: + words = line.split() + if len(words) > 1 and words[0] == 'default': + if '.' in words[1]: + interface['v4']['gateway'] = words[1] + interface['v4']['interface'] = words[5] + elif ':' in words[1]: + interface['v6']['gateway'] = words[1] + interface['v6']['interface'] = words[5] return interface['v4'], interface['v6']