.. _juniper_junos_rpc: juniper_junos_rpc +++++++++++++++++ Execute one or more NETCONF RPCs on a Junos device .. versionadded:: 2.0.0 .. contents:: :local: :depth: 2 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 is ``get-software-information``. Requirements ------------ The following software packages must be installed on hosts that execute this module: * `junos-eznc `_ >= 2.1.7 * Python >= 2.7 .. _module-specific-options-label: Module-specific Options ----------------------- The following options may be specified for this module: .. raw:: html
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
  • text
  • xml
  • json
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
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
  • yes
  • no
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

Common Connection-related Options --------------------------------- In addition to the :ref:`module-specific-options-label`, the following connection-related options are also supported by this module: .. raw:: html
parameter type required default choices comments
attempts
int no 10
The number of times to try connecting and logging in to the Junos device. This option is only applicable when using mode = 'telnet' or mode = 'serial'. Mutually exclusive with the console option.
baud
int no 9600
The serial baud rate, in bits per second, used to connect to the Junos device. This option is only applicable when using mode = 'serial'. Mutually exclusive with the console option.
console
str no none
An alternate method of specifying a NETCONF over serial console connection to the Junos device using Telnet to a console server. The value of this option must be a string in the format --telnet <console_hostname>,<console_port_number>. This option is deprecated. It is present only for backwards compatibility. The string value of this option is exactly equivalent to specifying host with a value of <console_hostname>, mode with a value of telnet, and port with a value of <console_port_number>. Mutually exclusive with the mode, port, baud, and attempts options.
host
str yes {{ inventory_hostname }}
The hostname or IP address of the Junos device to which the connection should be established. This is normally the Junos device itself, but is the hostname or IP address of a console server when connecting to the console of the device by setting the mode option to the value telnet. This option is required, but does not have to be specified explicitly by the user because it defaults to {{ inventory_hostname }}.

aliases: hostname, ip
mode
str no none
  • none
  • telnet
  • serial
The PyEZ mode used to establish a NETCONF connection to the Junos device. A value of none uses the default NETCONF over SSH mode. Depending on the values of the host and port options, a value of telnet results in either a direct NETCONF over Telnet connection to the Junos device, or a NETCONF over serial console connection to the Junos device using Telnet to a console server. A value of serial results in a NETCONF over serial console connection to the Junos device. Mutually exclusive with the console option.
passwd
str no The first defined value from the following list 1) The ANSIBLE_NET_PASSWORD environment variable. (used by Ansible Tower) 2) The value specified using the -k or --ask-pass command line arguments to the ansible or ansible-playbook command. 3) none (An empty password/passphrase)
The password, or ssh key's passphrase, used to authenticate with the Junos device. If this option is not specified, authentication is attempted using an empty password, or ssh key passphrase.

aliases: password
port
int or str no 830 if mode = none, 23 if mode = 'telnet', '/dev/ttyUSB0' if (mode = 'serial')
The TCP port number or serial device port used to establish the connection. Mutually exclusive with the console option.
provider
dict no
An alternative syntax for specifying the connection options. Rather than specifying each connection-related top-level option, the connection-related options may be specified as a dictionary of suboptions to the provider option. All connection-related options must either be specified as top-level options or as suboptions of the provider option. You can not combine the two methods of specifying connection-related options.
Dictionary object provider
parameter type required default choices comments
baud
int no 9600
The serial baud rate, in bits per second, used to connect to the Junos device. This option is only applicable when using mode = 'serial'. Mutually exclusive with the console option.
attempts
int no 10
The number of times to try connecting and logging in to the Junos device. This option is only applicable when using mode = 'telnet' or mode = 'serial'. Mutually exclusive with the console option.
console
str no none
An alternate method of specifying a NETCONF over serial console connection to the Junos device using Telnet to a console server. The value of this option must be a string in the format --telnet <console_hostname>,<console_port_number>. This option is deprecated. It is present only for backwards compatibility. The string value of this option is exactly equivalent to specifying host with a value of <console_hostname>, mode with a value of telnet, and port with a value of <console_port_number>. Mutually exclusive with the mode, port, baud, and attempts options.
passwd
str no The first defined value from the following list 1) The ANSIBLE_NET_PASSWORD environment variable. (used by Ansible Tower) 2) The value specified using the -k or --ask-pass command line arguments to the ansible or ansible-playbook command. 3) none (An empty password/passphrase)
The password, or ssh key's passphrase, used to authenticate with the Junos device. If this option is not specified, authentication is attempted using an empty password, or ssh key passphrase.
ssh_config
path no
The path to the SSH client configuration file. If this option is not specified, then the PyEZ Device instance by default queries file ~/.ssh/config.
host
str yes {{ inventory_hostname }}
The hostname or IP address of the Junos device to which the connection should be established. This is normally the Junos device itself, but is the hostname or IP address of a console server when connecting to the console of the device by setting the mode option to the value telnet. This option is required, but does not have to be specified explicitly by the user because it defaults to {{ inventory_hostname }}.
mode
str no none
  • none
  • telnet
  • serial
The PyEZ mode used to establish a NETCONF connection to the Junos device. A value of none uses the default NETCONF over SSH mode. Depending on the values of the host and port options, a value of telnet results in either a direct NETCONF over Telnet connection to the Junos device, or a NETCONF over serial console connection to the Junos device using Telnet to a console server. A value of serial results in a NETCONF over serial console connection to the Junos device. Mutually exclusive with the console option.
timeout
int no 30
The maximum number of seconds to wait for RPC responses from the Junos device. This option does NOT control the initial connection timeout value.
ssh_private_key_file
path no The first defined value from the following list 1) The ANSIBLE_NET_SSH_KEYFILE environment variable. (used by Ansible Tower) 2) The value specified using the --private-key or --key-file command line arguments to the ansible or ansible-playbook command. 3) none (the file specified in the user's SSH configuration, or the operating-system-specific default)
The path to the SSH private key file used to authenticate with the Junos device. If this option is not specified, and no default value is found using the algorithm below, then the SSH private key file specified in the user's SSH configuration, or the operating-system-specific default is used.
port
int or str no 830 if mode = none, 23 if mode = 'telnet', '/dev/ttyUSB0' if (mode = 'serial')
The TCP port number or serial device port used to establish the connection. Mutually exclusive with the console option.
user
str yes The first defined value from the following list 1) The ANSIBLE_NET_USERNAME environment variable. (used by Ansible Tower) 2) The remote_user as defined by Ansible. Ansible sets this value via several methods including a) -u or --user command line arguments to the ansible or ansible-playbook command. b) ANSIBLE_REMOTE_USER environment variable. c) remote_user configuration setting. See the Ansible documentation for the precedence used to set the remote_user value. 3) The USER environment variable.
The username used to authenticate with the Junos device. This option is required, but does not have to be specified explicitly by the user due to the algorithm for determining the default value.
ssh_config
path no
The path to the SSH client configuration file. If this option is not specified, then the PyEZ Device instance by default queries file ~/.ssh/config.
ssh_private_key_file
path no The first defined value from the following list 1) The ANSIBLE_NET_SSH_KEYFILE environment variable. (used by Ansible Tower) 2) The value specified using the --private-key or --key-file command line arguments to the ansible or ansible-playbook command. 3) none (the file specified in the user's SSH configuration, or the operating-system-specific default)
The path to the SSH private key file used to authenticate with the Junos device. If this option is not specified, and no default value is found using the algorithm below, then the SSH private key file specified in the user's SSH configuration, or the operating-system-specific default is used.

aliases: ssh_keyfile
timeout
int no 30
The maximum number of seconds to wait for RPC responses from the Junos device. This option does NOT control the initial connection timeout value.
user
str yes The first defined value from the following list 1) The ANSIBLE_NET_USERNAME environment variable. (used by Ansible Tower) 2) The remote_user as defined by Ansible. Ansible sets this value via several methods including a) -u or --user command line arguments to the ansible or ansible-playbook command. b) ANSIBLE_REMOTE_USER environment variable. c) remote_user configuration setting. See the Ansible documentation for the precedence used to set the remote_user value. 3) The USER environment variable.
The username used to authenticate with the Junos device. This option is required, but does not have to be specified explicitly by the user due to the algorithm for determining the default value.

aliases: username

Common Logging-related Options ------------------------------ In addition to the :ref:`module-specific-options-label`, the following logging-related options are also supported by this module: .. raw:: html
parameter type required default choices comments
level
str no WARNING
  • INFO
  • DEBUG
The level of information to be logged can be modified using this option
1) By default, messages at level WARNING or higher are logged.
2) If the -v or --verbose command-line options to the ansible-playbook command are specified, messages at level INFO or higher are logged.
3) If the -vv (or more verbose) command-line option to the ansible-playbook command is specified, or the ANSIBLE_DEBUG environment variable is set, then messages at level DEBUG or higher are logged.
4) If level is mentioned then messages at level level or more are logged.
logdir
path no none
The path to a directory, on the Ansible control machine, where debugging information for the particular task is logged.
If this option is specified, debugging information is logged to a file named {{ inventory_hostname }}.log in the directory specified by the logdir option.
The log file must be writeable. If the file already exists, it is appended. It is the users responsibility to delete/rotate log files.
The level of information logged in this file is controlled by Ansible's verbosity, debug options and level option in task
1) By default, messages at level WARNING or higher are logged.
2) If the -v or --verbose command-line options to the ansible-playbook command are specified, messages at level INFO or higher are logged.
3) If the -vv (or more verbose) command-line option to the ansible-playbook command is specified, or the ANSIBLE_DEBUG environment variable is set, then messages at level DEBUG or higher are logged.
4) If level is mentioned then messages at level level or more are logged.
The logfile and logdir options are mutually exclusive. The logdir option is recommended for all new playbooks.

aliases: log_dir
logfile
path no none
The path to a file, on the Ansible control machine, where debugging information for the particular task is logged.
The log file must be writeable. If the file already exists, it is appended. It is the users responsibility to delete/rotate log files.
The level of information logged in this file is controlled by Ansible's verbosity, debug options and level option in task
1) By default, messages at level WARNING or higher are logged.
2) If the -v or --verbose command-line options to the ansible-playbook command are specified, messages at level INFO or higher are logged.
3) If the -vv (or more verbose) command-line option to the ansible-playbook command is specified, or the ANSIBLE_DEBUG environment variable is set, then messages at level DEBUG or higher are logged.
4) If level is mentioned then messages at level level or more are logged.
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 logfile 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 logdir option in new playbooks. The logfile and logdir options are mutually exclusive.

aliases: log_file

.. _juniper_junos_rpc-examples-label: 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="" 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 ########## Return Values ------------- .. raw:: html
name description returned type sample
attrs
The RPC attributes and values from the list of dictionaries in the attrs option. This will be none if no attributes are applied to the RPC.
always dict
changed
Indicates if the device's state has changed. Since this module doesn't change the operational or configuration state of the device, the value is always set to false.
You could use this module to execute an RPC which changes the operational state of the the device. For example, clear-ospf-neighbor-information. Beware, this module is unable to detect this situation, and will still return a changed value of false in this case.
success bool
failed
Indicates if the task failed. See the results key for additional details.
always bool
format
The format of the RPC response from the list of formats in the formats option.
always str
kwargs
The keyword arguments from the list of dictionaries in the kwargs option. This will be none if no kwargs are applied to the RPC.
always dict
msg
A human-readable message indicating the result.
always str
parsed_output
The RPC reply from the Junos device parsed into a JSON datastructure. For XML replies, the response is parsed into JSON using the jxmlease library. For JSON the response is parsed using the Python json library.
When Ansible converts the jxmlease or native Python data structure into JSON, it does not guarantee that the order of dictionary/object keys are maintained.
when RPC executed successfully, return_output is true, and the RPC format is xml or json. dict
results
The other keys are returned when a single RPC is specified for the rpcs option. When the value of the rpcs option is a list of RPCs, this key is returned instead. The value of this key is a list of dictionaries. Each element in the list corresponds to the RPCs in the rpcs option. The keys for each element in the list include all of the other keys listed. The failed key indicates if the individual RPC failed. In this case, there is also a top-level failed key. The top-level failed key will have a value of false if ANY of the RPCs ran successfully. In this case, check the value of the failed key for each element in the results list for the results of individual RPCs.
when the rpcs option is a list value. list of dict
rpc
The RPC which was executed from the list of RPCs in the rpcs option.
always str
stdout
The RPC reply from the Junos device as a single multi-line string.
when RPC executed successfully and return_output is true. str
stdout_lines
The RPC reply from the Junos device as a list of single-line strings.
when RPC executed successfully and return_output is true. list of str


Notes ----- .. note:: - The NETCONF system service must be enabled on the target Junos device. Author ~~~~~~ * Juniper Networks - Stacy Smith (@stacywsmith) Status ~~~~~~ This module is flagged as **stableinterface** which means that the maintainers for this module guarantee that no backward incompatible interface changes will be made.