aoscx-ansible-role
aoscx-ansible-role copied to clipboard
Getting mac address in lldp_neighbors with ansible fact aoscx_fact
I have this ansible playbook to get lldp information and I'd like to retrieve the mac_addr of a lldp neighbor Here is the code:
- hosts: all
roles:
- role: arubanetworks.aoscx_role
tasks: - name: Retrieve all information from the device and save into a variable "facts_output" aoscx_facts: gather_network_resources: ['interfaces'] register: facts_output
- set_fact:
var_port_list: "{{facts_output['ansible_facts']['ansible_net_interfaces']['line_card,1/1']}}"
- set_fact:
var_lldp: "{{item.value['lldp_neighbors']}}"
var_port: "{{item.key}}"
with_dict: "{{var_port_list}}"
when: item.value['lldp_neighbors'] != None
- debug: var="{{var_lldp}}"
Here is the output: TASK [debug] ************************************************************************************************************************************************************************************************* ok: [aoscx_1] => { "var_lldp": { "32383170-3133-4D32-3231-313030365254,94:40:c9:ac:b5:c0": { "chassis_id": "32383170-3133-4D32-3231-313030365254", "dcbx_application_priorities": {}, "mac_addr": "94:40:c9:ac:b5:c0", "med_network_policy": {}, "neighbor_info": { "chassis_capability_available": " ", "chassis_capability_enabled": " ", "chassis_description": "ProLiant DX360 Gen10 10NVMe", "chassis_id_len": "36", "chassis_id_subtype": "local", "chassis_index": "16", "chassis_name": "", "chassis_protocol": "LLDP", "chassis_refcount": "2", "chassis_ttl": "100", "mgmt_iface_list": "0,0", "mgmt_ip_list": "10.1.1.10,b4:7a:f1:55:31:5a", "port_description": "Undefined Slot, Port 1", "port_hidden_in": "0", "port_hidden_out": "0", "port_id_len": "6", "port_id_subtype": "link_local_addr", "port_lastchange": "60bc298a", "port_lastupdate": "60bec29e", "port_mfs": "0", "port_protocol": "LLDP", "remote_index": 1 }, "neighbor_info_organizational": {}, "port_id": "94:40:c9:ac:b5:c0" } } }
Question: How can I get the mac_addr from this dict object?
I try var_lldp['mac_addr] but get an error stating that the dict_object has no mac_addr attribute
Thanks for helping