From affbab8e3f6038297346c30f83dddd6f3e334eab Mon Sep 17 00:00:00 2001 From: Nathaniel Case Date: Wed, 16 May 2018 09:54:24 -0400 Subject: [PATCH] ios_facts: Add check to skip lldp neighbors if lldp doesn't exist or isn't enabled. (#40247) * Add check to skip lldp neighbors if lldp doesn't exist or isn't enabled. * Re-enable check_rc on ios' run_commands (cherry picked from commit 39bed45bafb3032ab9f482f87634e69b8259a17f) --- lib/ansible/module_utils/network/ios/ios.py | 10 ++++++++-- lib/ansible/modules/network/ios/ios_facts.py | 4 +++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/ansible/module_utils/network/ios/ios.py b/lib/ansible/module_utils/network/ios/ios.py index e609528f609..fc690c98fd4 100644 --- a/lib/ansible/module_utils/network/ios/ios.py +++ b/lib/ansible/module_utils/network/ios/ios.py @@ -29,7 +29,7 @@ import json from ansible.module_utils._text import to_text from ansible.module_utils.basic import env_fallback, return_values from ansible.module_utils.network.common.utils import to_list, ComplexList -from ansible.module_utils.connection import Connection +from ansible.module_utils.connection import Connection, ConnectionError _DEVICE_CONFIGS = {} @@ -144,7 +144,13 @@ def run_commands(module, commands, check_rc=True): prompt = None answer = None - out = connection.get(command, prompt, answer) + try: + out = connection.get(command, prompt, answer) + except ConnectionError as e: + if check_rc: + raise + else: + out = e try: out = to_text(out, errors='surrogate_or_strict') diff --git a/lib/ansible/modules/network/ios/ios_facts.py b/lib/ansible/modules/network/ios/ios_facts.py index 1384f313d5c..a6016453809 100644 --- a/lib/ansible/modules/network/ios/ios_facts.py +++ b/lib/ansible/modules/network/ios/ios_facts.py @@ -281,7 +281,9 @@ class Interfaces(FactsBase): self.populate_ipv6_interfaces(data) data = self.responses[3] - if data: + lldp_errs = ['Invalid input', 'LLDP is not enabled'] + + if data and not any(err in data for err in lldp_errs): neighbors = self.run(['show lldp neighbors detail']) if neighbors: self.facts['neighbors'] = self.parse_neighbors(neighbors[0])