Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

Example: Require and Restrict Configuration Statements

Junos OS commit scripts enforce custom configuration rules. When a candidate configuration is committed, it is inspected by each active commit script. This example uses a commit script to specify required and prohibited configuration statements.

Requirements

This example uses a device running Junos OS that has the Ethernet management interface fxp0.

Overview and Commit Script

This example shows how to use a commit script to specify required and prohibited configuration statements. The following commit script ensures that the Ethernet management interface (fxp0) is configured and detects when the interface is improperly disabled. The script also detects when the bgp statement is not included at the [edit protocols] hierarchy level. In all cases, the script generates an error message, and the commit operation fails.

The example script is shown in both XSLT and SLAX syntax:

XSLT Syntax

SLAX Syntax

Configuration

Procedure

Step-by-Step Procedure

To download, enable, and test the script:

  1. Copy the script into a text file, name the file no-nukes.xsl or no-nukes.slax as appropriate, and copy it to the /var/db/scripts/commit/ directory on the device.

  2. Select the following test configuration stanzas, and press Ctrl+c to copy them to the clipboard.

    If you are using the SLAX version of the script, change the filename at the [edit system scripts commit file] hierarchy level to no-nukes.slax.

  3. In configuration mode, issue the load merge terminal command to merge the stanzas into your device configuration.

    1. At the prompt, paste the contents of the clipboard by using the mouse and the paste icon.

    2. Press Enter.

    3. Press Ctrl+d.

  4. Commit the configuration.

Verification

Verifying Commit Script Execution

Purpose

Verify that the script behaves as expected.

Action

Review the output of the commit command. The script requires that the Ethernet management interface (fxp0) is configured and enabled and that the bgp statement is included at the [edit protocols] hierarchy level. The sample configuration stanzas include the fxp0 interface but disable it. In addition, the bgp statement is not configured at the [edit protocols] hierarchy level. When you run the script, it generates an error, and the commit operation fails. The following output appears after issuing a commit command: