如何解决没有将正则表达式与 ansible 匹配
我正在尝试使用正则表达式获取设备 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 举报,一经查实,本站将立刻删除。