I'am trying to get the list of the device ID and the list of the port Id with ansible with regex but i get an empty list, below the output that i'am trying to parse it :
Device ID Local Intrfce Holdtme Capability Platform Port ID
hello.fr.com #(this is in line separatly)
Fa 3/1/1 400 R S I XXXX Gi 3/3 #(and this in the next line)
cdp.fr.com
Fa 0/0/1 600 R S I XXXX Gi 3/3
Total cdp entries displayed : 2
and here my code:
tasks:
- name: get neighbors
ios_command:
commands:
- show cdp neighbors
register: output
- set_fact:
reg_address: '(\S+[.]\S+[.]\S+[.]\S+)\s+'
reg_ports: '\s+\S+\s\S+\s+\d+\s+\w\s\w\s\w\s+\S+\s+(\S+\s\d+[/]\d+)'
- set_fact:
List_interfaces: []
List_ports: []
- set_fact:
List_interfaces: "{{List_interfaces + item | string | regex_search(reg_address, '\\1') }}"
loop: "{{output.stdout_lines[0]}}"
when: "{{ List_interfaces | length }} > 0"
- set_fact:
List_ports: "{{List_ports + item | string | regex_search(reg_ports, '\\1') }}"
loop: "{{ output.stdout_lines[0] }}"
when: "{{ List_ports | length }} > 0"