10-12-2022 12:35 PM
I want to create a DNAC velocity template where I can go through the ports of each switch in the stack and IF the interface contains the command "switchport access vlan 1" or "switchport access vlan 1" or "switchport access vlan 3", issue the statement "no spanning-tree portfast", else dont do anything.
I have created a draft as below where I go through the stack by entering how many stacks there are and the range I want. If under that stack I find that switchport access command, I want to execute the no spanning-tree portfast. Not sure how the syntax would go for velocity over here.
#foreach($switch in [1..${stack_member_count}])
interface range GigabitEthernet${switch}/0/1-$Ports
#if ($var == "switchport access vlan 1")
no spanning-tree portfast
#end
#end
10-13-2022 08:14 AM
This sounds like a change you are planning to make only once. The Day-N automation tools aren't designed that way. With just a few exceptions, the automation process can't read the existing config on the switch to make a decision.
Instead, consider how you would create a template to reconfigure the entire switch, in a repeatable way, including having the admin tell the switch which interfaces are in vlan 1,2,3, etc rather the admin asking the switch for that information.
10-13-2022 02:40 PM - edited 10-13-2022 03:24 PM
Yes its a change I'll do once, I have used many templates to get the change done once if its a repetitive change. I have sseen IF Else statement where it actually does read existing configs and makes a decision, is there any documentation to your claim ? that would be useful, thanks.
So far I can use a forloop to enter the commands on a particular interface I enter, but cant seem to use the IF command successfully. since I dont have an IF statement, I used the code 3 times or can use it more to enter the desired interface or interface range to get the job done. IF statement would have been usefull, thats what I'm after
#set ($port1 = $port_number_format1)
#foreach($switch in [${port1}])
interface range GigabitEthernet${switch}
no spanning-tree portfast
#end
#set ($port2 = $port_number_format2)
#foreach($switch in [${port2}])
interface range GigabitEthernet${switch}
no spanning-tree portfast
#end
#set ($port3 = $port_number_format3)
#foreach($switch in [${port3}])
interface range GigabitEthernet${switch}
no spanning-tree portfast
#end
10-13-2022 03:08 PM
I didn't say it was impossible, just that it helps to understand how the system is designed. It does not read the config as it provisions. But it does have a copy of the config from the last time it synced and it extracts some interface information that you can access with built in system variables. interface.description is a common one, and for your purposes you can use interface.vlanid. Try this in your simulator to see what I mean:
#foreach($i in $__interface)
interface $i.portName
portMode is $i.portMode
portType is $i.portType
description is $i.description
vlanID is $i.vlanId
voiceVlan is $i.voiceVlan
#end
10-18-2022 02:28 AM
As stated by @Preston Chilcote , you should be able to use the System Template Variables to do this, although it might take a bit of bending..
For every interface in a list of interfaces (list of interfaces can be taken from said variables)..
##..Bear in mind, this will take a list of all physical/virtual interfaces, so you need to make subsequent conditionals to check for the correct interfaces
if this vlanId for this port is in [1,2,3]..
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide