From 0f4cf8cb431d4e6530bb0cd8ddffd64bf89179e3 Mon Sep 17 00:00:00 2001 From: Boris Manojlovic Date: Tue, 10 Mar 2015 15:19:29 +0100 Subject: [PATCH 1/2] add missing AIX network facts discovery --- lib/ansible/module_utils/facts.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lib/ansible/module_utils/facts.py b/lib/ansible/module_utils/facts.py index 9781bb53ae0..a281717f2eb 100644 --- a/lib/ansible/module_utils/facts.py +++ b/lib/ansible/module_utils/facts.py @@ -2180,6 +2180,34 @@ class AIXNetwork(GenericBsdIfconfigNetwork, Network): else: self.parse_unknown_line(words, current_if, ips) + rc, out, err = module.run_command(['/usr/bin/uname', '-W']) + # don't bother with wpars it does not work + # zero means not in wpar + if out.split()[0] == '0': + if current_if['macaddress'] == 'unknown' and re.match('^en', current_if['device']): + rc, out, err = module.run_command(['/usr/bin/entstat', current_if['device'] ]) + if rc != 0: + break + for line in out.split('\n'): + if not line: + pass + buff = re.match('^Hardware Address: (.*)', line) + if buff: + current_if['macaddress'] = buff.group(1) + + buff = re.match('^Device Type:', line) + if buff and re.match('.*Ethernet', line): + current_if['type'] = 'ether' + # device must have mtu attribute in ODM + if 'mtu' not in current_if: + rc, out, err = module.run_command(['/usr/sbin/lsattr','-El', current_if['device'] ]) + if rc != 0: + break + for line in out.split('\n'): + if line: + words = line.split() + if words[0] == 'mtu': + current_if['mtu'] = words[1] return interfaces, ips # AIX 'ifconfig -a' does not inform about MTU, so remove current_if['mtu'] here From a59784a5818655bb79967e98140908468d663065 Mon Sep 17 00:00:00 2001 From: Boris Manojlovic Date: Tue, 10 Mar 2015 19:44:39 +0100 Subject: [PATCH 2/2] don't use full path to command instead use module.get_bin_path --- lib/ansible/module_utils/facts.py | 63 +++++++++++++++++-------------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/lib/ansible/module_utils/facts.py b/lib/ansible/module_utils/facts.py index a281717f2eb..2d670e2816f 100644 --- a/lib/ansible/module_utils/facts.py +++ b/lib/ansible/module_utils/facts.py @@ -2179,35 +2179,40 @@ class AIXNetwork(GenericBsdIfconfigNetwork, Network): self.parse_inet6_line(words, current_if, ips) else: self.parse_unknown_line(words, current_if, ips) - - rc, out, err = module.run_command(['/usr/bin/uname', '-W']) - # don't bother with wpars it does not work - # zero means not in wpar - if out.split()[0] == '0': - if current_if['macaddress'] == 'unknown' and re.match('^en', current_if['device']): - rc, out, err = module.run_command(['/usr/bin/entstat', current_if['device'] ]) - if rc != 0: - break - for line in out.split('\n'): - if not line: - pass - buff = re.match('^Hardware Address: (.*)', line) - if buff: - current_if['macaddress'] = buff.group(1) - - buff = re.match('^Device Type:', line) - if buff and re.match('.*Ethernet', line): - current_if['type'] = 'ether' - # device must have mtu attribute in ODM - if 'mtu' not in current_if: - rc, out, err = module.run_command(['/usr/sbin/lsattr','-El', current_if['device'] ]) - if rc != 0: - break - for line in out.split('\n'): - if line: - words = line.split() - if words[0] == 'mtu': - current_if['mtu'] = words[1] + uname_path = module.get_bin_path('uname') + if uname_path: + rc, out, err = module.run_command([uname_path, '-W']) + # don't bother with wpars it does not work + # zero means not in wpar + if out.split()[0] == '0': + if current_if['macaddress'] == 'unknown' and re.match('^en', current_if['device']): + entstat_path = module.get_bin_path('entstat') + if entstat_path: + rc, out, err = module.run_command([entstat_path, current_if['device'] ]) + if rc != 0: + break + for line in out.split('\n'): + if not line: + pass + buff = re.match('^Hardware Address: (.*)', line) + if buff: + current_if['macaddress'] = buff.group(1) + + buff = re.match('^Device Type:', line) + if buff and re.match('.*Ethernet', line): + current_if['type'] = 'ether' + # device must have mtu attribute in ODM + if 'mtu' not in current_if: + lsattr_path = module.get_bin_path('lsattr') + if lsattr_path: + rc, out, err = module.run_command([lsattr_path,'-El', current_if['device'] ]) + if rc != 0: + break + for line in out.split('\n'): + if line: + words = line.split() + if words[0] == 'mtu': + current_if['mtu'] = words[1] return interfaces, ips # AIX 'ifconfig -a' does not inform about MTU, so remove current_if['mtu'] here