cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1592
Views
5
Helpful
8
Replies

DNAC template- How to use the vlan name to find vlan ID

junos2ios
Level 1
Level 1

Hello- I'm trying to use DayN template to configure switch port. All the vlans are created using Onboarding templates.

So in the config i have following vlans already provisioned on the switch

vlan 30
name VOICE-VLAN
!
vlan 40
name DATA-VLAN
!

 

so in my DayN template i'm able to use something like

 

interface range GigabitEthernet1/0/1-12
switchport mode access

switchport voice vlan name VOICE-VLAN

 

and it deploys the following 

 

interface range GigabitEthernet1/0/1

switchport mode access

switchport voice vlan 30

 

but for other port config like the one below vlan name is not supported. It has to be vlan id

 

interface range GigabitEthernet1/0/13-23

authentication event server dead action authorize vlan x

 

i could  use something like ${Data_Vlan} and have this info as input from the user but the vlan id is different in all locations so i didn't want to make this a variable that you have to input and remember the data vlan iD. 

 

Since this vlan already exist on the switch , is there a way to use the name and have it convert to vlan ID? any system variable to do something like this or another way? 

Hope this makes sense

TIA

 

8 Replies 8

But if vlan id is different for each location, then, you are going to need different templates for each location, right?  

Why you can´t just add on the template "authentication event server dead action authorize vlan 30" and apply on the switch?

i do have different Onboarding templates which configures different vlan IDs. i was hoping to use single DayN template to configure the ports with different vlans

markus.forrer
Level 4
Level 4

You could use Jinja Templates for this and define the variables inside the template

{% set VoiceVlanID = '30' %}

interface range GigabitEthernet1/0/13-23

authentication event server dead action authorize vlan {{ VoiceVlanID }}

 

Cheers

Markus

Thanks Markus- What i need is to look up vlan ID somehow as the ID could be different every time. I need something like 

i.e {% set VoiceVlanID = 'sh vlan name VOICE-VLAN ifindex ' %}

obviously this doesn't work but you get what i'm trying to do here

Click the link in the upper right of the template editor for Template System Variables.  I don't think you'll find anything vlan related, so it's unlikely you'll be able to do what you're hoping. Perhaps this is an opportunity to pick a new vlan to use everywhere for this purpose, to simplify the operation of your network going forward.

 

If you use a variable instead, keep in mind that you can build a CSV file to import to the provision process to populate all the variables automatically.  So you don't actually have to "manually" enter the vlan number for each site each time you provision.

Look at the screenshot. There is something related from the inventories

 

Screenshot 2022-04-27 at 19.25.59.png

I haven't tried yet, but at least there is something to test with

The easiest way to access those interface variables in your template, is something like this (so that you can avoid having to find the index)

 

#foreach( $int in $__interface )
$int.portName
#if ($int.description.contains("Cisco"))
#end

unfortunately this is a legacy environment and not easy to clean up . I only found  interface.vlanid in the variable ..thats not what i need. will just have to input the vlan id for now until we figure out another way.. thank you