aruba / aoscx-ansible-collection

Ansible collections for AOS-CX switches 
43 stars 23 forks source link

Feature request: Extend aoscx_facts for LLDP neighbors #79

Closed smirlach closed 6 months ago

smirlach commented 11 months ago

Hello,

i'd like to ask if it is possible to add a parameter to the aoscx_facts module to get all LLDP neighbors of a device similar to the CLI commands show lldp neighbor-infoor show lldp neighbor-info detail?

I know the LLDP neighbors are also somehow included with the _physicalinterfaces parameter, but it is no fun to iterate over all line cards and interfaces to get all of the LLDP neighbors. So this would be a very useful extension to me.

tchiapuziowong commented 11 months ago

Thank you for your feedback! I'll include this in our backlog and will update the issue once we have a planned development in place.

tchiapuziowong commented 11 months ago

@smirlach can you provide an example of how you'd like the data to be structured? A list, dictionary, list of dictionaries? An example like so would be greatly appreciated and will allow us to better plan/design this enhancement.

Example data:

[
{ "local_port": "1/1/1",
"chassis_id": "5c:b9:01:1d:00:00",
},
{ "local_port": "1/1/45",
"chassis_id": "90:20:c2:bb:9c:00",
},
]
smirlach commented 11 months ago

@tchiapuziowong I was thinking of a list of dictionaries, pretty much like your example. Including all information i also would get when running show lldp neighbor-info on the CLI. Here an example:

[
    {
        "local_port": "1/1/1",
        "chassis_id": "5c:b9:01:1d:00:00",
        "port_id": "Gi0",
        "port_desc": "GigabitEthernet0",
        "TTL": 120,
        "sys_name": "Host1.net"
    },
    {
        "local_port": "1/1/45",
        "chassis_id": "90:20:c2:bb:9c:00",
        "port_id": "Gi0",
        "port_desc": "GigabitEthernet0",
        "TTL": 120,
        "sys_name": "Host2.net"
    }
]
tchiapuziowong commented 6 months ago

This has been included in the latest collection version v4.3.1 - closing issue

smirlach commented 4 months ago

Hi @tchiapuziowong,

sorry for the late reply. I've updated the collection version to v4.3.1, but unfortunately the lldp_neighbors option doesn't work on my side. I get the following error message:

'Network resources: "PARAMETER ERROR: Wrong module name. LLDPNeighbor doesn''t exist"'

Further information:

Switch OS version: 10.10.1100

ansible-galaxy collection list | grep aruba
arubanetworks.aoscx       4.3.1  
ansible [core 2.13.9]
  config file = /Users/<user>/repos/test/ansible.cfg
  configured module search path = ['/Users/<user>/repos/test/library']
  ansible python module location = /Users/<user>/.pyenv/versions/3.9.6/lib/python3.9/site-packages/ansible
  ansible collection location = /Users/<user>/.ansible/collections:/usr/share/ansible/collections
  executable location = /Users/<user>/.pyenv/versions/3.9.6/bin/ansible
  python version = 3.9.6 (default, May 16 2023, 16:15:39) [Clang 14.0.3 (clang-1403.0.22.14.1)]
  jinja version = 3.1.2
  libyaml = True

Hostfile:

all:
  hosts:
    <hostname>:
      ansible_host: <hostname>
      ansible_user: <user>
      ansible_password: <password>
      ansible_network_os: arubanetworks.aoscx.aoscx
      ansible_connection: arubanetworks.aoscx.aoscx  # REST API via pyaoscx connection method
      ansible_aoscx_validate_certs: False
      ansible_aoscx_use_proxy: False
      ansible_acx_no_proxy: True
      ansible_aoscx_rest_version: 10.09

Playbook:

- hosts: all
  collections:
    - arubanetworks.aoscx
  vars:
    ansible_python_interpreter: /usr/bin/python3
  gather_facts: False
  tasks:
  - name: Gather LLDP information
    arubanetworks.aoscx.aoscx_facts:
      gather_network_resources: lldp_neighbors
    register: lldp

  - debug: var=lldp
tchiapuziowong commented 4 months ago

@smirlach can you remove the ansible_python_interpreter variable from your playbook & inventory? since you're using a virtual environment that wouldn't be where your modules are installed - to validate where your pyaoscx package is installed execute pip show pyaoscx

smirlach commented 4 months ago

@tchiapuziowong thank you, you brought me on the right track. The issue wasn't with the virtual environment, it was an outdated version of pyaoscx. I assumed that installing the new collection version also installed the required dependencies for the collection.