05-28-2024 12:31 AM
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!
Solved! Go to Solution.
05-28-2024 12:43 AM
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
05-28-2024 12:43 AM
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
05-28-2024 02:01 AM
Thanks alot, works perfectly!
05-28-2024 06:12 AM
You're so welcome @kattmatman
05-28-2024 07:35 AM
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.
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