From 39673dfc3797c22b13caeb1bbded47f76b653828 Mon Sep 17 00:00:00 2001 From: Paul Neumann Date: Wed, 10 Oct 2018 14:02:14 +0200 Subject: [PATCH] ios_facts: Fix minor aesthetical glitches (#46577) * ios_facts: Fix LLDP gathering without neighbors When LLDP is enabled but no neighbors are present, the following structure is generated: ... "ansible_net_neighbors": { "null": [ { "host": null, "port": null } ] }, ... If we are not able to find any relevant LLDP information, bail out early so cases like shown above are handled more gracefully. * ios_facts: Remove trailing space in lineprotocol Some Cisco devices (at least CSR1000V 16.6.4) add a space after the line protocol. This causes the space to be present in the result of fact gathering: "ansible_net_interfaces": { "GigabitEthernet2": { ... "lineprotocol": "up ", Be more clear about scanning the output to avoid this behaviour. --- lib/ansible/modules/network/ios/ios_facts.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/network/ios/ios_facts.py b/lib/ansible/modules/network/ios/ios_facts.py index 553219babd..ddbc479935 100644 --- a/lib/ansible/modules/network/ios/ios_facts.py +++ b/lib/ansible/modules/network/ios/ios_facts.py @@ -382,6 +382,8 @@ class Interfaces(FactsBase): if entry == '': continue intf = self.parse_lldp_intf(entry) + if intf is None: + return facts if intf not in facts: facts[intf] = list() fact = dict() @@ -447,7 +449,7 @@ class Interfaces(FactsBase): return match.group(1) def parse_lineprotocol(self, data): - match = re.search(r'line protocol is (.+)$', data, re.M) + match = re.search(r'line protocol is (\S+)\s*$', data, re.M) if match: return match.group(1)