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.
pull/46753/head
Paul Neumann 6 years ago committed by Peter Sprygada
parent 4ba0cfeb4b
commit 39673dfc37

@ -382,6 +382,8 @@ class Interfaces(FactsBase):
if entry == '': if entry == '':
continue continue
intf = self.parse_lldp_intf(entry) intf = self.parse_lldp_intf(entry)
if intf is None:
return facts
if intf not in facts: if intf not in facts:
facts[intf] = list() facts[intf] = list()
fact = dict() fact = dict()
@ -447,7 +449,7 @@ class Interfaces(FactsBase):
return match.group(1) return match.group(1)
def parse_lineprotocol(self, data): 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: if match:
return match.group(1) return match.group(1)

Loading…
Cancel
Save