cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
417
Views
3
Helpful
4
Replies

How to provision 24 or 48 port switch with one template?

kattmatman
Level 1
Level 1

Hi,

I want to provision both 24 ports and 48 ports C9300 with the same template and have the option to choose if the switch i'm provisioning has 24 or 48 ports in variables.

This doesn't work:

{% if '24' in NUM_OF_PORTS %}
interface range GigabitEthernet1/0/1-24
{% endif %}
!
{% if '48' in NUM_OF_PORTS %}
interface range GigabitEthernet1/0/1-48
{% endif %}
switchport access vlan
switchport mode access 2

What am I doing wrong?

Thanks in advance!

1 Accepted Solution

Accepted Solutions

M02@rt37
VIP
VIP

Hello @kattmatman 

Try this:

{% if NUM_OF_PORTS == '24' %}
interface range GigabitEthernet1/0/1-24
{% elif NUM_OF_PORTS == '48' %}
interface range GigabitEthernet1/0/1-48
{% endif %}
switchport access vlan 2
switchport mode access

--

Use '==' for exact string comparison

Use 'elif' for mutually exclusive conditions

 

 

 

Best regards
.ı|ı.ı|ı. If This Helps, Please Rate .ı|ı.ı|ı.

View solution in original post

4 Replies 4

M02@rt37
VIP
VIP

Hello @kattmatman 

Try this:

{% if NUM_OF_PORTS == '24' %}
interface range GigabitEthernet1/0/1-24
{% elif NUM_OF_PORTS == '48' %}
interface range GigabitEthernet1/0/1-48
{% endif %}
switchport access vlan 2
switchport mode access

--

Use '==' for exact string comparison

Use 'elif' for mutually exclusive conditions

 

 

 

Best regards
.ı|ı.ı|ı. If This Helps, Please Rate .ı|ı.ı|ı.

Thanks alot, works perfectly!

You're so welcome @kattmatman 

Best regards
.ı|ı.ı|ı. If This Helps, Please Rate .ı|ı.ı|ı.

Preston Chilcote
Cisco Employee
Cisco Employee

If you want to optimize even more, you can use built in variables to read the product ID to determine if there are 24 ports or 48 ports without having to ask the user to tell you.  This saves a few clicks during provision.  Sorry, I don't have a code snippet easily ready to share, but maybe someone else does.

Review Cisco Networking for a $25 gift card