Do not gather mem facts if command invalid (#40820) (#41141)

* Do not gather mem facts if command invalid (#40820)

* Do not gather mem facts if command invalid

In some firmwares, 'show memory statistics' fail, thus
do not populate mem if we got a failure after running that command.

* Fix pep8

* Warn if got error when running 'sh memory statistics'

* Fix pep8

(cherry picked from commit 669949e6a3)

* Update ios_facts.py (#40928)

Account for upper/lower case match occurrences of "[Nn]umber" and "[Ss]erial"

Model Number                       : WS-C3850-12X48U
System Serial Number          :  <removed>

(cherry picked from commit 12d221152b)

* Expand ios password prompt regex (#41131)


(cherry picked from commit 49fddb6f28)
pull/41144/merge
Nathaniel Case 7 years ago committed by Matt Davis
parent 72ad0dd4ec
commit 79cedcbaa5

@ -204,11 +204,11 @@ class Default(FactsBase):
return match.group(1) return match.group(1)
def parse_stacks(self, data): def parse_stacks(self, data):
match = re.findall(r'^Model number\s+: (\S+)', data, re.M) match = re.findall(r'^Model [Nn]umber\s+: (\S+)', data, re.M)
if match: if match:
self.facts['stacked_models'] = match self.facts['stacked_models'] = match
match = re.findall(r'^System serial number\s+: (\S+)', data, re.M) match = re.findall(r'^System [Ss]erial [Nn]umber\s+: (\S+)', data, re.M)
if match: if match:
self.facts['stacked_serialnums'] = match self.facts['stacked_serialnums'] = match
@ -228,6 +228,9 @@ class Hardware(FactsBase):
data = self.responses[1] data = self.responses[1]
if data: if data:
if 'Invalid input detected' in data:
warnings.append('Unable to gather memory statistics')
else:
processor_line = [l for l in data.splitlines() processor_line = [l for l in data.splitlines()
if 'Processor' in l].pop() if 'Processor' in l].pop()
match = re.findall(r'\s(\d+)\s', processor_line) match = re.findall(r'\s(\d+)\s', processor_line)
@ -446,6 +449,9 @@ FACT_SUBSETS = dict(
VALID_SUBSETS = frozenset(FACT_SUBSETS.keys()) VALID_SUBSETS = frozenset(FACT_SUBSETS.keys())
global warnings
warnings = list()
def main(): def main():
"""main entry point for module execution """main entry point for module execution
@ -508,7 +514,6 @@ def main():
key = 'ansible_net_%s' % key key = 'ansible_net_%s' % key
ansible_facts[key] = value ansible_facts[key] = value
warnings = list()
check_args(module, warnings) check_args(module, warnings)
module.exit_json(ansible_facts=ansible_facts, warnings=warnings) module.exit_json(ansible_facts=ansible_facts, warnings=warnings)

@ -64,7 +64,7 @@ class TerminalModule(TerminalBase):
if passwd: if passwd:
# Note: python-3.5 cannot combine u"" and r"" together. Thus make # Note: python-3.5 cannot combine u"" and r"" together. Thus make
# an r string and use to_text to ensure it's text on both py2 and py3. # an r string and use to_text to ensure it's text on both py2 and py3.
cmd[u'prompt'] = to_text(r"[\r\n]password: ?$", errors='surrogate_or_strict') cmd[u'prompt'] = to_text(r"[\r\n](?:Local_)?[Pp]assword: ?$", errors='surrogate_or_strict')
cmd[u'answer'] = passwd cmd[u'answer'] = passwd
cmd[u'prompt_retry_check'] = True cmd[u'prompt_retry_check'] = True
try: try:

Loading…
Cancel
Save