diff --git a/lib/ansible/modules/network/nxos/nxos_facts.py b/lib/ansible/modules/network/nxos/nxos_facts.py index f8ce57b96e6..ec12ce3d9b0 100644 --- a/lib/ansible/modules/network/nxos/nxos_facts.py +++ b/lib/ansible/modules/network/nxos/nxos_facts.py @@ -128,7 +128,7 @@ ansible_net_interfaces: returned: when interfaces is configured type: dict ansible_net_neighbors: - description: The list of LLDP neighbors from the remote device + description: The list of LLDP/CDP neighbors from the remote device returned: when interfaces is configured type: dict @@ -297,6 +297,10 @@ class Interfaces(FactsBase): if data: self.facts['neighbors'] = self.populate_neighbors(data) + data = self.run('show cdp neighbors detail', 'json') + if data: + self.facts['neighbors'] = self.populate_neighbors_cdp(data) + def populate_interfaces(self, data): interfaces = dict() for item in data['TABLE_interface']['ROW_interface']: @@ -347,6 +351,23 @@ class Interfaces(FactsBase): return objects + def populate_neighbors_cdp(self, data): + objects = dict() + data = data['TABLE_cdp_neighbor_detail_info']['ROW_cdp_neighbor_detail_info'] + + if isinstance(data, dict): + data = [data] + + for item in data: + local_intf = item['intf_id'] + objects[local_intf] = list() + nbor = dict() + nbor['port'] = item['port_id'] + nbor['sysname'] = item['device_id'] + objects[local_intf].append(nbor) + + return objects + def parse_ipv6_interfaces(self, data): try: data = data['TABLE_intf']