10-01-2024 05:41 AM
Hello, I was wondering if there is some manual for Cisco DNAC (using Jinja) and regexp expressions usage. Let me explain: I've DNAC onboarding scripts which provides initial configurations for catalyst 9300L and 9300UXG switches. I want the macro to only run (ergo exclude uplink ports) on user-ports
As we might have stack switches, the combinations are like this:
I've tried myriads of combinations which works elsewhere, but not in DNAC.
GigabitEthernet[1|2]/1/
GigabitEthernet[1|2]\/1\/
GigabitEthernet\d+/1/\d+
The macro condition is defined like this:
{% for intf in __interface %}
{% if intf.interfaceType.contains('Physical') and not intf.portName.contains('App') and not intf.portName.contains('GigabitEthernet0') and not intf.portName.contains("TenGigabitEthernet[1|2]\/1\/") and not intf.portName.contains("GigabitEthernet([1|2])/1")%}
interface {{intf.portName}}
....
Thank you for any suggestions
Solved! Go to Solution.
10-01-2024 04:00 PM - edited 10-01-2024 04:00 PM
I think you need to be using the .matches method instead of contains when doing more than just a basic string comparison.
10-01-2024 11:27 AM
This isn't well documented, but you cant use system variables in onboarding templates because system variables read info from Inventory stored during the last sync. A PnP device has yet to be onboarded, so this information is unavailable. This is one reason why we recommend simplifying your onboarding template as much as possible and use Day-N templates for the full production config. Your regex's should work in a Day-N template.
For more advice on best practices of Onboarding Templates
10-01-2024 11:36 AM
Thank you Preston,
I might have been wrong in the statement that we're onboarding the devices. The onboard process is already completed for them and I am using Day-N template to configure access ports via calling a macro. The problem I am having is that it's far from dummy proof script and I want it to only do this for user ports. Ergo every other port except 10G uplink (Tex/1/x) ports on the 9300L switches. The macro loop is running through __interface attaching example
10-01-2024 04:00 PM - edited 10-01-2024 04:00 PM
I think you need to be using the .matches method instead of contains when doing more than just a basic string comparison.
10-02-2024 07:21 AM
Thank you Preston, that was it
{% macro generate_ua_interface(functional_type,datavl='1',voicevl,includedotx='1') %}
{% for intf in __interface %}
{% if intf.portName.matches("GigabitEthernet[1|2|3|4|5]/0.*") or intf.portName.matches("TenGigabitEthernet[1|2|3|4|5]/0.*")%}
interface {{intf.portName}}
description User data/phone port
switchport mode access
switchport nonegotiate
switchport access vlan {{datavl}}
{% if functional_type == "UA" %}
switchport voice vlan {{voicevl}}
{% endif -%}
no shutdown
logging event link-status
load-interval 60
speed auto
duplex auto
spanning-tree portfast
snmp trap link-status
service-policy input pm_marking_notrust
service-policy output pm_queueing
{% if includedotx=='1' and functional_type == "UA"%}
authentication control-direction in
authentication event fail action next-method
authentication event server dead action reinitialize vlan {{datavl}}
authentication event server dead action authorize voice
authentication event server alive action reinitialize
authentication host-mode multi-auth
authentication open
authentication order mab dot1x
authentication priority dot1x mab
authentication port-control auto
authentication periodic
authentication timer reauthenticate server
mab
dot1x pae authenticator
dot1x timeout tx-period 10
{% endif %}
no shutdown
!
{% endif -%}
{% endfor %}
{% endmacro %}
10-02-2024 10:52 AM - edited 10-02-2024 10:52 AM
Cisco devnet has some github repositories you should look through. The best one may be:
https://developer.cisco.com/codeexchange/github/repo/kebaldwi/DNAC-TEMPLATES/
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