Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

Using Ansible with Junos PyEZ Tables to Retrieve Operational Information from Devices Running Junos OS

 

Understanding the juniper_junos_table Module and Junos PyEZ Tables

Junos PyEZ operational (op) Tables provide a simple and efficient way to extract information from complex operational command output, and the Junos PyEZ jnpr.junos.op module contains predefined Table and View definitions for some common operational commands. The juniper_junos_table Ansible module in the Juniper.junos role enables you to leverage Junos PyEZ op Tables from within Ansible playbooks. The juniper_junos_table module can use the predefined operational Tables that are included with the Junos PyEZ distribution or it can use user-defined operational Tables and Views to retrieve operational information from devices running Junos OS.

For general information about Junos PyEZ Tables and Views and for information about Junos PyEZ’s predefined operational Tables and Views, see Understanding Junos PyEZ Tables and Views and Junos PyEZ Predefined Operational Tables and Views in the Junos PyEZ Developer Guide.

Note

Starting in Ansible for Junos OS Release 2.0.0, the juniper_junos_table module replaces the functionality of the junos_get_table module.

Note

The juniper_junos_table module does not work with configuration Tables and Views.

Using the juniper_junos_table Module with Junos PyEZ Tables

The juniper_junos_table module requires one argument, file, which is the name of the YAML file that defines the Junos PyEZ Table and View. The default file path is the location of the predefined Junos PyEZ op Tables, which reside in the Junos PyEZ install path under the jnpr/junos/op directory. To specify a different directory, include the path argument and define the path to the directory containing the YAML file with the Table and View definitions. If a file contains multiple Table definitions or the file contains a single Table that does not include "Table" in its name, you must also include the table argument to specify the name of the Table that will be used to retrieve the data.

For example, the following task retrieves data by using a custom table named FPCTable, which is defined in the fpc.yaml file located in the playbook directory:

The juniper_junos_table module’s response includes the resource key, which contains a list of items returned by the Table. Each list item is a dictionary of the field names defined by the View and the value extracted from the data for each of the corresponding fields.

Consider the following predefined Table and View, ArpTable and ArpView, in the arp.yml file of the Junos PyEZ distribution. ArpTable executes the <get-arp-table-information> RPC with the <no-resolve/> option, which is equivalent to the show arp no-resolve CLI command. The corresponding View extracts the interface name, IP address, and MAC address for each <arp-table-entry> item in the response.

The following Ansible playbook executes the juniper_junos_table module, which uses ArpTable to retrieve Address Resolution Protocol (ARP) information from devices running Junos OS. Because ArpTable is included with the Junos PyEZ distribution and resides in the default directory for the predefined Junos PyEZ op Tables, the path module argument is not required to specify the file location. In addition, because ArpTable is the only Table defined in the file, the table argument is not required to specify the Table.

The playbook output, which is truncated for brevity, includes the corresponding fields, as defined by the View, for each <arp-table-entry> item returned by the device.

The following Ansible playbook leverages the predefined Junos PyEZ operational Table, OspfInterfaceTable to retrieve information about OSPF interfaces on devices running Junos OS. The ospf.yml file defines multiple Tables and Views, so the module call includes the table argument to specify which Table to use.

Specifying RPC Arguments

Junos PyEZ operational Tables have an optional args option that defines the default command options and arguments for the RPC executed by that Table. The application executes the RPC with the default options unless the user overrides the defaults. In Junos PyEZ applications, you can override the default command options or pass additional options and arguments to the RPC when calling the get() method.

The juniper_junos_table module also enables you to override the default command options defined in the Table or pass additional options and arguments to the PRC by using the kwargs argument. The kwargs value is a dictionary of command options and values, which must be supported by the RPC and the device on which the RPC is executed.

For example, the predefined Junos PyEZ op Table EthPortTable in the ethport.yml file executes the <get-interface-information> RPC with the media command option and returns information for all interfaces that match the given regular expression for the interface name.

The following Ansible playbook uses EthPortTable to extract information about the interfaces on devices running Junos OS. The kwargs argument includes interface_name: "ge-1/0/0", which overrides the EthPortTable default for interface_name and instructs the module to retrieve the requested fields for only the ge-1/0/0 interface.

For more information about the default and user-supplied command options and arguments in Junos PyEZ Tables, see Defining Junos PyEZ Operational Tables and Using Junos PyEZ Operational Tables and Views.

Release History Table
Release
Description
Starting in Ansible for Junos OS Release 2.0.0, the juniper_junos_table module replaces the functionality of the junos_get_table module.