如何使用 Ansible 将使用 TextFSM 的输出解析为多个列表?

问题描述

如何使用 Ansible 将带有 TextFSM 的输出解析为多个列表?

Ansible 任务:

        - name: Register output
          nxos_command:
            commands: show running-config dhcp
          register: output

        - name: Parsing show command
          set_fact:
            ip_add: "{{ output.stdout[0] | parse_cli_textfsm('./templates/output.textfsm') }}"

        - name: Print output
          debug:
            msg: ip_add
@H_502_6@

交换机上的配置:

nxos-1# show running-config dhcp

interface Ethernet1/1
  ip dhcp relay address 10.1.1.2

interface Ethernet1/2
  ip dhcp relay address 10.1.1.3
  ip dhcp relay address 10.1.1.4

interface Ethernet1/3
  ip dhcp relay address 10.1.1.5
  ip dhcp relay address 10.1.1.6
  ip dhcp relay address 10.1.1.7

nxos-1#
@H_502_6@

需要输出的是每个接口下的ip列表:

"ip_add": [
        "10.1.1.2",]
        [
        "10.1.1.3","10.1.1.4",]
        [
        "10.1.1.5"
        "10.1.1.6","10.1.1.7",]
@H_502_6@

我应该在 output.textfsm 中添加什么以获得所需的输出

Value <some value>

Start
  <parse the value into multiple lists>
@H_502_6@

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)