cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1727
Views
0
Helpful
3
Replies

Template Loop With Range Not Working

In advance of deploying DNAC I'm trying to figure out VTL, but can't get loops to work when using variables. This is on one of the reserved instances of DNAC on Devnet. I got the idea from this post by Adam Radford

Even when I try exactly what he does in the blog post, the simulation has zero output

 

#set ($stack_member_count = $stack_count)

#foreach($switch in [1..${stack_member_count}])
interface Ten${switch}/0/1
#uplink_interface
#end

 

What I'm trying to get working is this

 

#macro (access_interface)
switchport host
switchport access vlan $access_vlan
switchport voice vlan $voice_vlan
#end

$first_access_port
$last_access_port
$access_vlan
$voice_vlan

#foreach($port in [${first_access_port}..${last_access_port}])
int gig1/0/$port
#access_interface
#end

3 Replies 3

Preston Chilcote
Cisco Employee
Cisco Employee

There's an important line in that post, "It is important to define the data type of $stack_count as an integer."  When I tested with it as a string (default) it also gave me no output (using Adam's example).  When I changed to int, I got ouptut

Thanks for the reply, but the variable is defined as an integer. It's possible the problem is with the sandbox, and not with the syntax. 

 

Outside the sandbox is there a way for me to check my syntax? I can't seem to find a VTL tester online, and I don't know Java. 

Ya, that could be it. I copied and pasted the desired template that you specified, and didn't have any issues.  But I'm testing on 1.3 and I think the devnet sandboxes are 1.2.10.   I don't have a 1.2.10 to play with at the moment. Here is part of the output I got from your template from the simulator.

 

int gig1/0/1
switchport host
switchport access vlan 4
switchport voice vlan 2

int gig1/0/2
switchport host
switchport access vlan 4
switchport voice vlan 2

....