Defining and Enforcing Configuration Rules with Commit Scripts

Being able to restrict network configurations in accordance with custom configuration rules can reduce human error and improve network uptime and reliability. Commit scripts allow you to enforce custom configuration rules.

This section contains the following topics:

Commit Script Overview

Commit scripts run each time a new candidate configuration is committed and inspect the configuration. If a candidate configuration does not adhere to your design rules, a commit script can instruct the services router to perform various actions, including the following:

Consider the following examples of actions you can perform with commit scripts:

The scripting language you use for writing commit scripts is Extensible Stylesheet Language Transformations (XSLT). XSLT commit scripts are based on Junos XML protocol Extensible Markup Language (XML).

Enabling Commit Scripts

To enable commit scripts:

  1. Write a commit script.

    For information about writing commit scripts, see the Junos Configuration and Operations Automation Guide.

  2. Copy the script to the /var/db/scripts/commit directory.

    Only users with superuser privileges can access and edit files in the /var/db/scripts/commit directory.

  3. Navigate to the top of the configuration hierarchy in either the J-Web or CLI configuration editor.
  4. Perform the configuration tasks described in Table 47.
  5. If you are finished configuring the network, commit the configuration.

Table 47: Enabling Commit Scripts

Task

J-Web Configuration Editor

CLI Configuration Editor

Navigate to the Commit level in the configuration hierarchy.

  1. In the J-Web interface, select CLI Tools>Point and Click CLI.
  2. Next to System, click Configure or Edit.
  3. Next to Scripts, click Configure or Edit.
  4. Next to Commit, click Configure or Edit.

From the [edit] hierarchy level, enter

edit system scripts commit

Enable the commit script file—for example, commit-script.xsl.

  1. Next to File, click Add new entry.
  2. In the File name box, type commit-script.xsl.
  3. Click OK.

Set the script file name:

set file commit-script.xsl

Disabling Commit Scripts

If you do not want a commit script to run, you can disable it by deleting or deactivating it in the configuration. Deleting a commit script permanently removes it from the configuration. To run the script later, you must reenable the script as described in Enabling Commit Scripts. Deactivating a commit script disables the script until you activate it later.

To delete a commit script:

  1. From configuration mode in the CLI, enter the following command:

    user@host# delete system scripts commit filename.xsl
  2. Commit the configuration:

    user@host# commit
    commit complete

To deactivate a commit script:

  1. From configuration mode in the CLI, enter the following command:

    user@host# deactivate system scripts commit filename.xsl
  2. Commit the configuration:

    user@host# commit
    commit complete

    Note: You can later reactivate the commit script using the activate system scripts commit filename.xsl command.