juniper_junos_command¶
Execute one or more CLI commands on a Junos device
New in version 2.0.0.
Synopsis¶
- Execute one or more CLI commands on a Junos device.
- 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.
Requirements¶
The following software packages must be installed on hosts that execute this module:
- junos-eznc >= 2.5.0
- Python >= 2.7
Module-specific Options¶
The following options may be specified for this module:
parameter | type | required | default | choices | comments |
---|---|---|---|---|---|
commands |
list | yes | none |
A list of one or more CLI commands to execute on the Junos device.
aliases: cli, command, cmd, cmds
|
|
dest |
path | no | None |
The path to a file, on the Ansible control machine, where the output of the cli command will be saved.
The file must be writeable. If the file already exists, it is overwritten.
When tasks are executed against more than one target host, one process is forked for each target host. (Up to the maximum specified by the forks configuration. See forks for details.) This means that the value of this option must be unique per target host. This is usually accomplished by including
{{ inventory_hostname }} in the value of the dest option. It is the user's responsibility to ensure this value is unique per target host.For this reason, this option is deprecated. It is maintained for backwards compatibility. Use the dest_dir option in new playbooks. The dest and dest_dir options are mutually exclusive.
aliases: destination
|
|
dest_dir |
path | no | None |
The path to a directory, on the Ansible control machine, where the output of the cli command will be saved. The output will be logged to a file named
{{ inventory_hostname }}_ command. format in the directory specified by the value of the dest_dir option.The destination file must be writeable. If the file already exists, it is overwritten. It is the users responsibility to ensure a unique dest_dir value is provided for each execution of this module within a playbook.
The dest_dir and dest options are mutually exclusive. The dest_dir option is recommended for all new playbooks.
aliases: destination_dir, destdir
|
|
formats |
str or list of str | no | text |
|
The format of the reply for the CLI command(s) specified by the commands option. The specified format(s) must be supported by the target Junos device. The value of this option can either be a single format, or a list of formats. If a single format is specified, it applies to all command(s) specified by the commands option. If a list of formats are specified, there must be one value in the list for each command specified by the commands option. Specifying the value
xml for the formats option is similar to appending | display xml to a CLI command, and specifying the value json for the formats option is similar to appending | display json to a CLI command.aliases: format, display, output
|
ignore_warning |
bool, str, or list of str | no | none |
A boolean, string or list of strings. If the value is
true , ignore all warnings regardless of the warning message. If the value is a string, it will ignore warning(s) if the message of each warning matches the string. If the value is a list of strings, ignore warning(s) if the message of each warning matches at least one of the strings in the list. The value of the ignore_warning option is applied to the load and commit operations performed by this module. |
|
return_output |
bool | no | True |
|
Indicates if the output of the command should be returned in the module's response. You might want to set this option to
false , and set the dest_dir option, if the command output is very large and you only need to save the output rather than using it's content in subsequent tasks/plays of your playbook. |
Examples¶
---
- name: Examples of juniper_junos_command
hosts: junos-all
connection: local
gather_facts: no
roles:
- Juniper.junos
tasks:
- name: Execute single "show version" command.
juniper_junos_command:
commands: "show version"
register: response
- name: Print the command output
debug:
var: response.stdout
- name: Execute three commands.
juniper_junos_command:
commands:
- "show version"
- "show system uptime"
- "show interface terse"
register: response
- name: Print the command output of each.
debug:
var: item.stdout
with_items: "{{ response.results }}"
- name: Two commands with XML output.
juniper_junos_command:
commands:
- "show route"
- "show lldp neighbors"
format: xml
- name: show route with XML output - show version with JSON output
juniper_junos_command:
commands:
- "show route"
- "show version"
formats:
- "xml"
- "json"
- name: save outputs in dest_dir
juniper_junos_command:
commands:
- "show route"
- "show version"
dest_dir: "./output"
- name: save output to dest
juniper_junos_command:
command: "show system uptime"
dest: "/tmp/{{ inventory_hostname }}.uptime.output"
- name: save output to dest
juniper_junos_command:
command:
- "show route"
- "show lldp neighbors"
dest: "/tmp/{{ inventory_hostname }}.commands.output"
- name: Multiple commands, save outputs, but don't return them
juniper_junos_command:
commands:
- "show route"
- "show version"
formats:
- "xml"
- "json"
dest_dir: "/tmp/outputs/"
return_output: false