juniper_junos_rpc¶
Execute one or more NETCONF RPCs on a Junos device
New in version 2.0.0.
Synopsis¶
- Execute one or more NETCONF RPCs on a Junos device.
- Use the
| display xml rpc
modifier to determine the equivalent RPC name for a Junos CLI command. For example,show version | display xml rpc
reveals the equivalent RPC name isget-software-information
.
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 |
---|---|---|---|---|---|
attrs |
dict or list of dict | no | none |
The attributes and values to the RPCs specified by the rpcs option. The value of this option can either be a single dictionary of keywords and values, or a list of dictionaries containing keywords and values.
There is a one-to-one correspondence between the elements in the kwargs list and the RPCs in the rpcs list. In other words, the two lists must always contain the same number of elements.
aliases: attr
|
|
dest |
path | no | None |
The path to a file, on the Ansible control machine, where the output of the RPC 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 dest value. 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 RPC will be saved. The output will be logged to a file named
{{ inventory_hostname }}_ rpc.format in the dest_dir directory.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
|
|
filter |
str | no | none |
This argument only applies if the rpcs option contains a single RPC with the value
get-config . When used, this value specifies an XML filter used to restrict the portions of the configuration which are retrieved. See the PyEZ get_config method for details on the value of this option.aliases: filter_xml
|
|
formats |
str or list of str | no | xml |
|
The format of the reply for the RPCs specified by the rpcs 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 RPCs specified by the rpcs option. If a list of formats are specified, there must be one value in the list for each RPC specified by the rpcs option.
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. |
|
kwargs |
dict or list of dict | no | none |
The keyword arguments and values to the RPCs specified by the rpcs option. The value of this option can either be a single dictionary of keywords and values, or a list of dictionaries containing keywords and values.
There must be a one-to-one correspondence between the elements in the kwargs list and the RPCs in the rpcs list. In other words, the two lists must always contain the same number of elements. For RPC arguments which do not require a value, specify the value of True as shown in the :ref:`juniper_junos_rpc-examples-label`.
aliases: kwarg, args, arg
|
|
return_output |
bool | no | True |
|
Indicates if the output of the RPC 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 RPC 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. |
rpcs |
list | yes | none |
A list of one or more NETCONF RPCs to execute on the Junos device.
aliases: rpc
|
Examples¶
---
- name: Examples of juniper_junos_rpc
hosts: junos-all
connection: local
gather_facts: no
roles:
- Juniper.junos
tasks:
- name: Execute single get-software-information RPC.
juniper_junos_rpc:
rpcs: "get-software-information"
register: response
- name: Print the RPC's output as a single multi-line string.
debug:
var: response.stdout
###### OLD EXAMPLES ##########
- junos_rpc:
host={{ inventory_hostname }}
rpc=get-interface-information
dest=get_interface_information.conf
register=junos
- junos_rpc:
host={{ inventory_hostname }}
rpc=get-interface-information
kwargs="interface_name=em0"
format=xml/text/json
dest=get_interface_information.conf
register=junos
# Example to fetch device configuration
- name: Get Device Configuration
junos_rpc:
host={{ inventory_hostname }}
rpc=get-config
dest=get_config.conf
# Fetch configuration over console server connection using PyEZ >= 2.0
- name: Get Device Configuration
junos_rpc:
host={{ inventory_hostname }}
port=7005
mode='telnet'
rpc=get-config
dest=get_config.conf
# Example to fetch device configuration
- name: Get Device Configuration for interface
junos_rpc:
host={{ inventory_hostname }}
rpc=get-config
filter_xml="<configuration><interfaces/></configuration>"
dest=get_config.conf
register: junos
# Example to fetch configuration in json for >=14.2
# and use it with rpc_reply
- name: Get Device Configuration
hosts: all
roles:
- Juniper.junos
connection: local
gather_facts: no
tasks:
- name: Get interface information
junos_rpc:
host: "{{ inventory_hostname }}"
rpc: get-interface-information
kwargs:
interface_name: em0
media: True
format: json
dest: get_interface_information.conf
register: junos
- name: Print configuration
debug: msg="{{ junos.rpc_reply }}"
###### OLD EXAMPLES ##########