如何在Junos_module命令中解决无法使用管道的问题

时间:2018-04-05 02:28:04

标签: ansible junos-automation

我正在尝试使用ansible在Juniper设备上自动执行某些命令。但是这些命令要求我使用' |' (管道)。读取Junos_command模块documentation,无法使用管道。

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命令ssh到所述设备和运行命令(不依赖于junos_command模块的),但是这似乎是一个大量的工作,我通过不使用放弃很多有用functioality的模块。

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

1 个答案:

答案 0 :(得分: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