This is a Privilege based feature: The user will be able to access, view, add, edit, delete, execute & export, only if privileges have been given by the administrator. This will be defined under roles and privileges.
This menu is accessible only if the below privilege has been checked.
From “Templates” menu click “Configuration Templates”.
Configuration Template Grid page, lists down all templates created by the user and also the templates which are assigned to the same user by admin or template management full privileged user.
The Access Control List feature in this module lets the admin privileged users to decide who can view, edit or delete any specific templates in NCCM.
Configuration Template Grid shows
NOTE: When the Template is used in Upload Job by a white listed user or Approver, Approval Process will be by-passed and Job will go for execution directly.
Configuration changes like “Provisioning”, “OS Upgrade”, “Service Creation”, “Service Deactivation” and “any change” on Networking Devices can be done using Configuration Templates.
Template Execution
User will be given Direct CLI (SSH or Telnet) access to the Devices from NCCM Application (like a Gateway process) for changing configurations.
How to write Command Portion in Template
NCCM supports two ways of writing commands in Template
conf t
hostname newname
exit
XML Command Format
In XML command format, each command is enclosed in XML node and additional input to the command like command timeout, prompt, expected pattern, previous match, action will be added in XML node properties.
<command prompt=”#” timeout=”10”>conf t</command>
<command prompt=”#” timeout=”10”>hostname newname</command>
<command prompt=”#” timeout=”10” action=”exit”>exit</command>
XML Command Syntax
<command property1=”value” property2=”value”> Device Command </command >
property1=”value” property2=”value” : Command properties
Device Command : Actual command
XML Command Sample
<command prompt=”#” timeout=”10”> hostname newname</command>
The device command for every device will be inside the Data portion of XML Node and the additional properties or information will be inside XML’s property portion. Property value must always be inside Double quotes character.
NCCM supports the following properties
prompt=”#”
prompt=” #”
prompt=”Router27#”
prompt=”[Are you confirm the reboot action]?”
prompt=”\.”
Follow the URL https://regex101.com/ to verify or check the regex pattern before saving the template.
prompt=”[#,>,\$]”
prompt=”[Username, login, User]”
action=”exit”
action=”output-to-store”
shell=”remote”
<command shell="remote" prompt="Password"> ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null {{Profile.ssh_loginname}}@{{Device.IPaddress}} -p {{Profile.ssh_port}} </command>
error_pattern="[Unknown command, Invalid Command]"
Example: when “copy tftp” command is not supported by a device, response will be %Error opening tftp and the error_pattern to catch the error will be
error_pattern="[%Error opening tftp]"
The below properties also follow the same principle as error_pattern .
expected_pattern="[bgp is enabled]"
expected_any_response="
expected_empty_response=""
expected_count_response="5"
NCCM expects a 5 line response.
expected_count_response="!5"
NCCM expects the response to be anything other than 5 lines.
expected_count_response=">5"
NCCM expects the response to be greater than 5 lines.
expected_count_response="<5"
NCCM expects the response to be less than 5 lines.
expected_count_response=">=5"
NCCM expects the response to be more than 4 lines.
expected_count_response="<=5"
NCCM expects the response to be less than 6 lines
For example:
If the output of the command, show IP interface brief is required to store in NCCM as Interface Brief, XML command should be written as
<command prompt=”#” timeout=”5” type=”Interface Brief”> show IP interface brief</command>
Sample command to shut down an interface in plain text and XML format.
Plain Format |
XML Format |
conf t int Gi 0/0 shutdown exit |
<command prompt=”#” timeout=”10”>conf t</command> <command prompt=”#” timeout=”10”> int Gi 0/0 </command> <command prompt=”#” timeout=”10”>shutdown</command> <command prompt=”#” timeout=”10” action=”exit”>exit</command> |
Sample command to enable syslog in plain text format and XML format.
Plain Format |
XML Format |
conf t logging source-interface Loopback100 end write memory |
<command prompt=”#” timeout=”10”>conf t</command> <command prompt=”#” timeout=”10”> logging source-interface Loopback100 </command> <command prompt=”#” timeout=”10”>end</command> <command prompt=”#” timeout=”10” action=”exit”>write memory</command> |
Below are some sample commands to replace the Device configuration file from NCCM server.
<command prompt="\]\?">copy tftp: running-config</command>
<command prompt="\]\?">{{Global.managementIP}}</command>
<command prompt="\]\?">{{Job.uploadfilename}}</command>
<command prompt="[\],#]" timeout="300">running-config</command>
<command previous_match="\]" prompt="#" timeout="300">yes</command>
<command action="exit" prompt="">exit</command>
NOTE: Plain text command cannot be written since the timeout of some commands are more than 30 seconds.
NCCM also supports writing of Comments inside the command portion, for better understanding of commands. To define a line as a comment, add # character at the beginning of a line.
Example for writing Comments inside commands:
# Make Terminal Len 0
<command prompt="#" timeout="60">terminal length 0</command>
# Copy the Image to Flash
<command prompt="]\?" timeout="60">copy tftp flash:</command>
# Remove boot system
<command prompt="#" timeout="60">no boot system</command>
NOTE: At the time of execution, NCCM ignores all lines starting with # (comment lines)
NCCM Variable Substitution
NCCM follows Jinja2 Template engine for converting command templates into actual commands. Jinja2 Template engine provides features like
Variable Substitution:
Variables are command inputs given by a user dynamically during the execution time.
For example, if the user wants to change the hostname in Cisco devices, the command syntax will be
#hostname <New Hostname>
hostname is the command and <New hostname> is the variable or input portion to hostname command
Through variable substitution, single template is enough to change hostname of all devices same Vendor and OS Type configured in template; else each device requires a separate template.
To substitute a variable, follow the below steps, based on the condition applicable:
<command prompt=”#” timeout=“5”>hostname {{Runtime.hostame}} </command>
Runtime is a substitution object.
{% if Runtime.hostname. == “router27” %}
NCCM Substitution Objects in Template:
NCCM supports 10 types of substitution objects for Variable substitution within configuration template
Runtime object will be used in Configuration Upload and Network Diagnosis activities. Runtime object variables will be converted into user input form to get values while configuring upload task or Network Diagnosis creation.
Ex {{Runtime.hostname}}
All Global parameters configured in NCCM are available through Global object for Variable substitution.
Ex {{Global.managementIP}}
Defines the field, based on the variable type specified such as Text Area, Text field, DropDown, Multi DropDown.
Ex : Type.Speed=DropDown
The default value for Type Object I defined here.
Ex: Default.Speed=10,100,1000
Displays the Text on mouse hover on the Variable Name.
Ex: Remark.Speed=enter speed of interface
If variable is declared ‘Optional’, the input for the field is not mandatory.
Ex: Optional.VariableName
Ensures that the Input format matches the defined format.
Ex: In Textfield, it should allow only 1 to 255
^([1-9]|[1-9][0-9]|[1-2][0-5][0-5])$
LOCAL_SHELL object gets values from LOCAL_ACCOUNT profile, configured in Device credential for Variable substitution.
Ex {{LOCAL_SHELL.username}}
Device object gets values from Device database of corresponding Device where command execution takes place.
Ex {{Device.IPaddress}}
Interface object gets values from Device Interface database of the corresponding Device where command execution takes place.
Ex {{Interface.name}}
Ex {{Interface.description}}
Job object gets values from Job Database (Upload or Download Job) of corresponding Device where command execution takes place.
Ex {{Job.name}}
Profile object gets values from Profile Database (Configuration Profile) of corresponding Device where command execution takes place.
Ex {{Profile.download_profile.user_name}}
Trigger object gets values from Configuration Trigger Database of corresponding Trigger name used in Configuration Template.
Ex {{Trigger.triggername}}
Note: A template can have more than one Trigger variable.
Profile object gets values from Device Credential Database of corresponding Device (Device Credential) where command execution will take place.
Ex {{Profile.ssh_loginname}}
Time object gets values from NCCM server based on current time which is for substituting time values in a template during execution
Ex {{Time.now}} – Time in unix epoc format
{{Time.YYYYMMDD}} – Time in YYYY MM DD format
{{Time.uniquestring}} – Unique string
Conditioning in Template:
NCCM supports condition based Templating using “if”, “if else” and “if elif else” conditional statements
{% if Runtime.interface_name == "GigabitEthernet0/0" %}
IP address 192.168.1.1 255.0.0.0
no shutdown
{% endif %}
{% if Runtime.interface_name == "GigabitEthernet0/0" %}
IP address 192.168.1.1 255.0.0.0
no shutdown
{% else %}
IP address 192.168.2.1 255.0.0.0
no shutdown
{% endif %}
{% if Runtime.interface_name == "GigabitEthernet0/0" %}
IP address 192.168.1.1 255.0.0.0
no shutdown
{% elif Runtime.interface_name == "GigabitEthernet0/1" %}
IP address 192.168.1.1 255.0.0.0
no shutdown
{% else %}
IP address 192.168.2.1 255.0.0.0
no shutdown
{% endif %}
Looping in Template:
NCCM supports loop based Templating using “for” loop statements
”For Loop” Condition:
{% for interface_name in Runtime.interface_names %}
{% if {{interface_name}} == "GigabitEthernet0/0" %}
IP address 192.168.1.1 255.0.0.0
no shutdown
{% endif %}
{% endfor %}
Guidelines for Configuration Template:
#Substitution, Conditioning, Looping in Template should be in Jinja2 standard. Refer http://jinja.pocoo.org/docs/2.10/ for more tutorials.
Points to Remember
Always enclose the commands within {% %} for "if" and "for", "while" conditional statements
Always enclose the variables inside {{ }} for substitution
Sample Template Configuration
Example 1: Create an Empty List and add values into List and DO a simple ‘For Loop’
# Declaring a string variable to store value from Runtime or user. Default (“”) function will make variable empty string till USER input
{% set myinput = Runtime.interface_list | default(“”) %}
# Converting User Input to a list using Split function
{% set mylist = myinput .split(",") %}
#Doing for Loop or Looping of Each Item
{% for each_interface in mylist %}
<command prompt="#">int {{each_interface}}</command>
<command prompt="#">shutdown</command>
# for requires endfor to close the section
{% endfor %}
Example 2: Conditions (if case elif Case and else case)
{% for each_interface in mylist %}
{% if each_interface == "Gi0/1" %}
<command prompt="#">int {{each_interface}}</command>
<command prompt="#">shutdown</command>
{% elif each_interface == "Gi0/2" %}
<command prompt="#">int {{each_interface}}</command>
<command prompt="#">no shutdown</command>
{% else %}
<command prompt="#">I dont know</command>
{% endif %}
{% endfor %}
Example 3: Taking List Input from a Trigger
#down_interface_list_cisco_ios is a Trigger in Configuration Trigger
{% set mylist1 = Trigger.down_interface_list_cisco_ios | default([]) %}
{% for each_interface in mylist1 %}
<command prompt="#">int {{each_interface}}</command>
<command prompt="#">shutdown</command>
{% endfor %}
Example 4: Disable the Interface named ‘Ether’
# String Manipulation startswith, endswith, find, lower, upper, strip
{% set myinput = Runtime.InterfaceNames | default ("") %}
{% set mylist = myinput.split(",") %}
{% for each_item in mylist %}
{% if each_item.lower().startswith("ether") %}
<command prompt="#">int {{each_item}}</command>
<command prompt="#">shutdown</command>
{% endif %}
{% endfor %}
Example 5: Taking First Element from the Trigger
{% set mylist = Trigger.down_interface_list_cisco_ios | default ([]) %}
{% if mylist %}
<command timeout ="10" prompt ="#" >config t</command>
<command timeout ="10" prompt ="#" >interface {{mylist[0]}} </command>
<command timeout="10" prompt ="#" >IP address 172.17.230.2 255.255.255.252</command>
<command timeout ="10" prompt ="#" >no shut</command>
{% endif %}