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 39bed45baf)
pull/40250/head
Nathaniel Case 7 years ago committed by GitHub
parent f1fc7cf384
commit affbab8e3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -29,7 +29,7 @@ import json
from ansible.module_utils._text import to_text from ansible.module_utils._text import to_text
from ansible.module_utils.basic import env_fallback, return_values 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.network.common.utils import to_list, ComplexList
from ansible.module_utils.connection import Connection from ansible.module_utils.connection import Connection, ConnectionError
_DEVICE_CONFIGS = {} _DEVICE_CONFIGS = {}
@ -144,7 +144,13 @@ def run_commands(module, commands, check_rc=True):
prompt = None prompt = None
answer = 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: try:
out = to_text(out, errors='surrogate_or_strict') out = to_text(out, errors='surrogate_or_strict')

@ -281,7 +281,9 @@ class Interfaces(FactsBase):
self.populate_ipv6_interfaces(data) self.populate_ipv6_interfaces(data)
data = self.responses[3] 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']) neighbors = self.run(['show lldp neighbors detail'])
if neighbors: if neighbors:
self.facts['neighbors'] = self.parse_neighbors(neighbors[0]) self.facts['neighbors'] = self.parse_neighbors(neighbors[0])

Loading…
Cancel
Save