summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEgor Margineanu <egmar@users.noreply.github.com>2020-12-08 01:31:29 +0100
committerGitHub <noreply@github.com>2020-12-07 18:31:29 -0600
commit847a2c87e5c7bcbfae803e3ca94ce08ace56ac4f (patch)
tree2000b420c31ceefde6598ec7485b0c435d883eb1
parentd852fa4135dd089cd3a45cd6a19507924376444b (diff)
downloadansible-847a2c87e5c7bcbfae803e3ca94ce08ace56ac4f.tar.gz
Fix AIX networks facts when nestat is either missing or has incorrect permissions (#72516) (#72713)
* Added check for none on netstat_path variable * Added changelog (cherry picked from commit e879f12fb9629842f6c9c1a18ebd9dfd3e23de32)
-rw-r--r--changelogs/fragments/72516-fix-aix-network-facts.yml2
-rw-r--r--lib/ansible/module_utils/facts/network/aix.py27
2 files changed, 16 insertions, 13 deletions
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 0000000000..2efb597278
--- /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 46bbb68f67..e9c90c6413 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):
+ interface = dict(v4={}, v6={})
+
netstat_path = self.module.get_bin_path('netstat')
- rc, out, err = self.module.run_command([netstat_path, '-nr'])
+ if netstat_path:
+ 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]
+ 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']