问题描述
我正在尝试使用正则表达式获取设备 ID 列表和端口 ID 列表,但我得到了所有行,在我试图解析它的输出下方:
print(sum_recursive([]))
>> 0
这里是我的代码:
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
tasks:
- name: get neighbors
ios_command:
commands:
- show cdp neighbors
register: output
- set_fact:
reg_address: '(\S+)\s+'
reg_ports: '\s+\S+\s+\d+\s+\w\s\w\s\w\s+\S+\s+(\S+\s\S+)'
- 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"
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)