0

我正在尝试使用 ansible 在瞻博网络设备上自动执行某些命令。但是命令要求我使用'|' (管道)。阅读 Junos_command 模块文档,无法使用管道。

This module does NOT use the Junos CLI to execute the CLI command. Instead, it uses the <command> RPC over a NETCONF channel. The <command> RPC takes a CLI command as it’s input and is very similar to executing the command on the CLI, but you can NOT include any pipe modifies (i.e. | match, | count, etc.) with the CLI commands executed by this module.

我尝试使用转义字符\,但它仍然不起作用。

我想到的是通过 ansible 使用原始 shell 命令来 ssh 到设备并运行命令(独立于 junos_command 模块),但这似乎需要做很多工作,而且我放弃了很多有用的功能,因为不使用该模块。

我可以使用哪些其他方法来使用此模块实际通过管道传递命令。

4

1 回答 1

1

您可以将输出返回为 XML 格式,而无需管道过滤。例如:

    - name: show bgp summary with XML output
      juniper_junos_command:
        commands:
          - "show bgp summary"
        formats:
          - "xml"
      register: response

然后使用 ansible xml_module 对返回的输出进行 xpath 过滤。

https://docs.ansible.com/ansible/2.4/xml_module.html

于 2018-11-28T12:29:33.120 回答