cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
8518
Views
5
Helpful
7
Replies

Cisco Prime using Database Variables in CLI Templates

Nicholas Poole
Level 1
Level 1

Has anyone ever got the following doc example to work?  I have changed it from shutdown a port to change the description as otherwise I would lose access to my switch (high quality example there Cisco) but nothing is deployed.  I have created an interface.properties file as stated.  What isn't clear is how exactly that interface.properties file gets invoked by that CLI template.  This section of the manual is poor to say the least.  Anybody been successful with this 'feature' ?

 

##############

 

Managing Database Variables in CLI Templates

You can use database (DB) variables for the following reasons:

  • DB variable is one of the data types in CLI templates. You can create DB variables to find the exact device and generate the accurate commands.
  • DB variables are predefined variables. All other variables are user-defined variables.
  • To view the predefined DB variables go to the following path:
    Cd/opt/CSCOlumos/conf/ifm/template/inventoryTagsInTemplate

Note You can find the CLITemplateDbVariablesQuery.properties file inside the InventoryTagsInTemplate folder that contains the list of predefined DB variables.


 

  • For example, SysObjectID, IPAddress, ProductSeries, ImageVersion are DB variables.When a device is added to Prime Infrastructure, the complete details of the device is collected in the DB variables. That is, the OID of the devices is collected in SysObjeectID, product series in ProductSeries, image versions of the device in ImageVersion, and so on.
  • Using the data collected by the DB variables, accurate commands can be generated to the device.
  • You can select the DB variable in the Type field (using the Managed Variables page). Expand the name field and fill in the default value field with any of the DB variables which you want to use.
  • When a device is discovered and added to Prime Infrastructure, you can use the database values that were gathered during the inventory collection to create CLI templates.

For example, if you want to create and deploy a CLI template to shut down all interfaces in a branch, create a CLI template that contains the following commands:

#foreach ($interfaceName in $interfaceNameList)
interface $interfaceName
shutdown
#end
 

where $interfaceNameList is the database variable type whose value will be retrieved from the database. $interfaceNameList has a default value of IntfName. You need to create the interfaceNameList variable as DB data type (using the managed variable dialog box) and add set the default to IntfName. If you have not specified a default value, you can specify it when you deploy the CLI template.

To populate interfaceNameList with the value from the database, you must create a properties file to capture the query string and save it in the /opt/CSCOlumos/conf/ifm/template/inventoryTagsInTemplate folder. This is a sample of a property file called interface.properties:

# for interface name tag->Name
IntfName=select name from EthernetProtocolEndpoint u where owningEntityId =
 

After you create the CLI template and the property file and deploy the CLI template, the following CLI is configured on the devices. This output assumes that the device has two interfaces (Gigabitethernet0/1 and Gigabitethernet0/0):

interface GigabitEthernet0/0
shutdown
interface GigabitEthernet0/1
shutdown

 

 

 

7 Replies 7

Hi Nicholas!,

did you get this configuration example to work?, I have the same issue :(

Best Regards!!

Hi,

does anyone was able to get the db values to work? What about the other values e.g. ProduktSeries? Can anyone provide some examples?

MARIO POIER
Level 4
Level 4

What is missing from the example is the fact that you need to create a Variable in the Manage Variable List for the $interfaceNameList object. Here is what I did:

Template Detail:

CLI Content:

#foreach ($interfaceName in $interfaceNameList)
        interface $interfaceName
             shutdown
        exit
#end

Next hightlight the interfaceNameList name and then click on the Manage Variables icon (upper right corner of the dialog). This will create a new variable of type String called interfaceNameList. Edit this new variable and change it to:

Type: DB

Default Value: IntfName

Note: IntfName was retrieved from the list of predefined variables listed in /opt/CSCOlumos/conf/ifm/template/inventoryTagsInTemplate mentioned above.

 

 

Thank you MARIO POIER

it worked fine with me but it only apply the commands under the physical interfaces

can we make any modification to apply the commands also under tunnel interfaces?

regards

Mahmoud

Hello, I want to test this on just 1 interface. I'm thinking I'd have to change #foreach to something else? When I went through the Deploy wizard I specified to only run on 1 interface (gi1/0/1), but during the summary all the interfaces were showing that they would be altered. 

Mehmet Can
Level 1
Level 1

I have same issue. I want use below cli template for my routers but i got error "Warning. No commands generated for this template" What's wrong?

 

Cli Temp Example:

 

#foreach ($interfaceName in $interfaceNameList)

interface $interfaceName

no ip redirects

no ip proxy-arp

no ip unreachables

no ip directed-broadcast

no ip mask-reply

no mop enabled

#end

bkennedy97
Level 1
Level 1

While the particular sample is dated material now, since this was relative to version 2.x for Prime Infrastructure, I have had success with implementing the database (DB) variables with Cisco Prime Infrastructure.  The DB variables do have some version dependencies, but the file is still located in the location listed within this doc.  In order to view/access it you have to be logged into the shell OS of CPI:

 

1) log into the CLI interface of Prime Infrastructure as admin

2) type shell in the command prompt, (if this is the first time you will be prompted to enter a new password)

3) enter the shell password

4) your command prompt should change to ade #

5) enter the following command to see the file in question of all the predefined DB variables.

   cat /opt/CSCOlumos/conf/ifm/template/inventoryTagsInTemplate/CLITemplateDbVariablesQuery.properties

 

This will display what each DB variable there is to use.  NOTE: the file and DB variables differ with version of Cisco Prime Infrastructure.

 

I recently created a template for password changes to the local admin accounts for our routers switches and firewalls.  Version of Cisco Prime Infrastructrure = 3.9

 

DB variables used were SoftwareVersion and ProductSeries.  You will set these as variables when you are creating your CLI template. (Configuration / Templates / Features & Technologies)

 

Here is what I created, since Apache VTL is similar to Javascript you can build out a lot of the configuration as follows:

Variables - below is a list of the variables that I created, it is important for the DB variables that you set the default value to match the DB variable.  So for SoftwareVersion you need to add the default value to be SoftwareVersion.

name = SoftwareVersion, type = DB, Display Label = verbose entry that explains what is going on, I advised to accept the defaults, required = true (although not necessary, but I marked the variables that are necessary to make the template work)

name = ProductVersion, type = DB

name = password, type = string

name = nx-os_password, type = string

 

Code - In order to leverage the logic so that Prime knows what to print out, I wanted to simplify the results for SoftwareVersion and ProductSeries, and found good results by matching on major releases of both IOS and IOS-XE.  I matched on ASA version 9 for the major release, but had to use ProductSeries for some of the Nexus switches that are still supported by CPI.

#if($SoftwareVersion.contains("15.")||$SoftwareVersion.contains("16.")||$SoftwareVersion.contains("17."))
username <local admin> privilege 15 algorithm-type scrypt secret $password
enable algorithm-type scrypt secret $password
#end
#if($SoftwareVersion.contains("12.2"))
username <local admin> privilege 15 secret $password
enable secret $password
#end
#if($SoftwareVersion.contains("9."))
username <local admin> password $password privilege 15
enable password $password
#end
#if($ProductSeries.contentEquals("Data Center Switches"))
username <local admin> password $password role network-admin
username admin password $nx-os_password role network-admin
#end

The end result is one deployment that will work for all of the devices that I help support.  Keep in mind that there are some limitations that you may have to test through, if it helps you can also use the preview/printout of what CPI is intending to execute for configuration.  During your testing you can also print out the DB variable of the current device that is selected from the preview page, click on the radial button to preview each device that you are testing.  If you want to see what Prime sees from the DB variables in question, just add them to your CLI content tab in your template.  $SoftwareVersion, $ProductSeries for this particular example.

 

Hope this helps for understanding.

 

Brandon

 

 

Review Cisco Networking for a $25 gift card