Latest Cisco, PMP, AWS, CompTIA, Microsoft Materials on SALE Get Now
Bulk VLAN Provisioning via Catalyst Center CLI Templates
4741

SPOTO Cisco Expert

SPOTO Cisco Expert

Settle a problem:41

Answered:

1.0 Problem Analysis

This document addresses a common technical challenge encountered when using CLI templates in Cisco Catalyst Center: the automated provisioning of a numerical range of VLANs on network devices. The core objective is to leverage a template to create multiple VLANs (e.g., VLAN 200 through 205) and assign their corresponding names in a single, automated operation, avoiding manual configuration for each VLAN.

The initial attempt to solve this involved using a foreach loop within the template editor, employing a range syntax ([200..205]) to define the iteration. This approach resulted in a template validation or deployment failure because the syntax is not recognized by the templating engine.

2.0 Root Cause Identification

The underlying issue stems from a misunderstanding of the templating language used by Cisco Catalyst Center. The CLI template engine primarily utilizes the Apache Velocity Templating Language (VTL). The [start..end] syntax for defining a numerical range is not a valid construct within VTL. This syntax is common in other programming or scripting languages (like Groovy) but will be rejected by the VTL parser, preventing the template from executing as intended. The engine requires an explicitly defined list or array of elements to iterate over.

3.0 Comprehensive Solution and Best Practices

To successfully provision a range of VLANs, a syntactically correct and scalable approach is required. The following sections detail the immediate fix and extend it with best practices for creating robust, reusable templates suitable for enterprise environments.

3.1 Immediate Syntactical Correction

The direct solution is to replace the invalid range syntax with an explicit array definition that is compliant with VTL. For a small, fixed set of VLANs, this is a quick and effective method.

Corrected VTL Template Code:

#set( $vlan_list = [200,201,202,203,204,205] )
!
#foreach( $vlan_id in $vlan_list )
vlan $vlan_id
 name VLAN_$vlan_id
!
#end
exit

In this corrected version, [200,201,202,203,204,205] is a valid VTL array. The #foreach loop correctly iterates through each element, generating the necessary vlan and name commands for each VLAN ID.

3.2 Enhancing Reusability with Template Variables (Recommended Practice)

While the explicit list is syntactically correct, it is not scalable or reusable. Hard-coding values within a template is poor practice. The superior approach is to parameterize the template using variables that are defined at the time of deployment. This allows the same template to be used for different devices or sites with varying VLAN requirements.

Step 1: Create a Parameterized Template

Modify the template to use a variable (e.g., $vlan_ids) that will be supplied during the provisioning workflow.

! Loop through the provided list of VLANs to create them
#foreach( $vlan_id in $vlan_ids )
vlan $vlan_id
 name VLAN_$vlan_id
!
#end
exit

Step 2: Define and Bind the Variable in Catalyst Center

  1. In the Catalyst Center Template Editor, save the template above.
  2. The editor will automatically detect $vlan_ids as an undefined variable. You will be prompted to define it.
  3. Define vlan_ids as a variable of type String. It is crucial to mark it as a “Required” and “Bind to a Variable” parameter.
  4. When you provision a device using this template, Catalyst Center will prompt you to provide a value for vlan_ids.
  5. In the value field, you will enter the VLANs as a comma-separated list within brackets: [200,201,202,203,204,205]

This method decouples the logic (the template) from the data (the VLAN list), which is a fundamental principle of network automation.

3.3 Advanced Method: Using Structured Data for Complex Requirements

For more complex scenarios where each VLAN requires a unique name that doesn’t follow a simple pattern, a more structured variable approach is recommended. This involves passing a JSON array of objects to the template.

Step 1: Advanced Parameterized Template

This template iterates through a list of VLAN objects, where each object contains both an id and a name.

! Loop through the provided structured VLAN data
#foreach( $vlan in $vlan_data )
vlan $vlan.id
 name $vlan.name
!
#end
exit

Step 2: Provide Structured Data During Provisioning

When provisioning, you would define the vlan_data variable and provide the value in JSON format:

[
  {"id": 200, "name": "CORP-DATA"},
  {"id": 201, "name": "CORP-VOICE"},
  {"id": 202, "name": "IOT-DEVICES"},
  {"id": 203, "name": "SECURE-MGMT"}
]

This advanced technique provides maximum flexibility and is the preferred method for managing configurations where multiple attributes per item are required.

4.0 Final Recommendations

For immediate, one-off tasks involving a small number of VLANs, the syntactically corrected explicit list is sufficient. However, for any production or scalable deployment, it is strongly recommended to use parameterized templates (Section 3.2 or 3.3). This approach aligns with automation best practices, enhances template reusability, and significantly reduces the potential for manual error. Always consider whether a CLI template is the appropriate tool; for standardized access port configurations as part of a fabric deployment, leveraging intent-based networking workflows and network profiles within Catalyst Center may provide a more integrated solution.

Don't Risk Your Certification Exam Success – Take Real Exam Questions
Pass the Exam on Your First Try? 100% Exam Pass Guarantee