0

I am trying to use ansible to automate some commands on a Juniper device. However the commands require me to use '|' (pipes). Reading over the Junos_command module documentation, pipes cannot be used.

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.

I tried using escape characters \, however it still does not work.

Something I thought of was using raw shell commands through ansible to ssh to the device and run the command (independent of the junos_command module), but this seems like a lot of work and I forego a lot of useful functioality by not using the module.

Which other methods can I employ to actually pass a command with a pipe using this module.

user2883071
  • 960
  • 1
  • 20
  • 50

1 Answers1

1

You can get the output back as XML format without pipe filtering. For example:

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

Then use ansible xml_module to xpath filter the returned output.

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

Jolly
  • 19
  • 4