diff --git a/changelogs/fragments/eos_facts-failure.yml b/changelogs/fragments/eos_facts-failure.yml new file mode 100644 index 00000000000..5c004fe4a70 --- /dev/null +++ b/changelogs/fragments/eos_facts-failure.yml @@ -0,0 +1,4 @@ +--- +bugfixes: + - eos_facts - fix failure when lldp will be disabled + (https://github.com/ansible/ansible/pull/42347) diff --git a/lib/ansible/module_utils/network/eos/eos.py b/lib/ansible/module_utils/network/eos/eos.py index 76903ab0ca2..2809abd163a 100644 --- a/lib/ansible/module_utils/network/eos/eos.py +++ b/lib/ansible/module_utils/network/eos/eos.py @@ -176,7 +176,12 @@ class Cli: prompt = None answer = None - out = connection.get(command, prompt, answer) + try: + out = connection.get(command, prompt, answer) + except ConnectionError as exc: + if check_rc: + raise + out = getattr(exc, 'err', exc) out = to_text(out, errors='surrogate_or_strict') try: @@ -338,7 +343,7 @@ class Eapi: return response - def run_commands(self, commands): + def run_commands(self, commands, check_rc=True): """Runs list of commands on remote device and returns results """ output = None @@ -493,9 +498,9 @@ def get_config(module, flags=None): return conn.get_config(flags) -def run_commands(module, commands): +def run_commands(module, commands, check_rc=True): conn = get_connection(module) - return conn.run_commands(to_command(module, commands)) + return conn.run_commands(to_command(module, commands), check_rc) def load_config(module, config, commit=False, replace=False): diff --git a/lib/ansible/modules/network/eos/eos_facts.py b/lib/ansible/modules/network/eos/eos_facts.py index 5dc7b203124..189a868f3f1 100644 --- a/lib/ansible/modules/network/eos/eos_facts.py +++ b/lib/ansible/modules/network/eos/eos_facts.py @@ -153,7 +153,7 @@ class FactsBase(object): self.responses = None def populate(self): - self.responses = run_commands(self.module, list(self.COMMANDS)) + self.responses = run_commands(self.module, list(self.COMMANDS), check_rc=False) class Default(FactsBase): @@ -258,7 +258,8 @@ class Interfaces(FactsBase): self.facts['interfaces'] = self.populate_interfaces(data) data = self.responses[1] - self.facts['neighbors'] = self.populate_neighbors(data['lldpNeighbors']) + if data: + self.facts['neighbors'] = self.populate_neighbors(data['lldpNeighbors']) def populate_interfaces(self, data): facts = dict()