Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

Using Salt to Compare the Junos OS Candidate Configuration with a Previously Committed Configuration

Juniper Networks provides support for using Salt to manage devices running Junos OS, and the Junos execution and state modules (for Salt) define functions that enable you to perform operational and configuration tasks on the managed devices. The salt.modules.junos.diff execution function and the salt.states.junos.diff state function enable you to compare the candidate configuration to a previously committed configuration and return the difference.

Note:

The ephemeral configuration database only stores the current version of the committed ephemeral configuration data, and as a result, it does not support comparing the current configuration to previously committed configurations.

Devices running Junos OS store a copy of the most recently committed configuration and up to 49 previous configurations. The junos.diff function returns the difference between the candidate configuration and a previously committed configuration, which is referenced by the rollback ID parameter. Table 1 outlines the rollback ID parameter to use for the junos.diff execution and state functions. If the rollback ID parameter is omitted, the rollback ID defaults to 0, which corresponds to the active or most recently committed configuration.

Table 1: Rollback ID Parameter

Function

Rollback ID Parameter

salt.modules.junos.diff

id

salt.states.junos.diff

d_id

The configuration differences are returned in patch format. Statements that exist only in the candidate configuration are prefixed with a plus sign (+), and statements that exist only in the comparison configuration and not in the candidate configuration are prefixed with a minus sign (-). If there is no difference between the configurations, the junos.diff function prints None.

To compare the candidate configuration to the active configuration, execute the junos.diff function, and either omit the rollback ID parameter or set it equal to 0. For example:

The previous command is equivalent to issuing the show | compare or show | compare rollback 0 configuration mode command in the Junos OS command-line interface (CLI).

If you compare the candidate configuration to a previous configuration and there are no differences, the junos.diff function returns None. In the following example, the junos.diff function compares the candidate configuration to the active configuration and returns None, which indicates that the there are no uncommitted changes in the candidate configuration:

To compare the candidate configuration to a specific rollback configuration, set the id parameter to the ID of the rollback configuration. This is equivalent to issuing the show | compare rollback n configuration mode command in the Junos OS CLI.

You can also define a state that returns the same information.

When you apply the state to one or more targets, it returns the differences for each target.