Rendered config , jinja not fully setting values in loops #17998
-
Hello All, I am attempting to work on configuration against a switch that does vlan ranges per interface. I am filtering through the tagged list to allow this to work and create the needed list. environment: goal is to have output such as
config render jinja template, with debug drop ins:
This config rendering though just loops fine but within the loop it seems to keep partly resetting itself to inital value and not keeping the 'end' value set options thoughout the loop itself. i have changed and edited the below to differnet locations within the script but have yet to find a way to keep it. {%- set start = vlan_list[0] %} below is the example rendering.
Any ideas why it would be resetting the end variable after the loop? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Various ideas:
|
Beta Was this translation helpful? Give feedback.
-
the i-1 does make sense and did allow some of the outputs to show more expected values but it is now cutting off last item, believe as the inital value is set to 0 we can ignore this as loop is just comparing current to 1 already. .
i did test with stand alone and another range. new list is however it still only ever uses the first value it finds in the start / end vars when setting the range values.
jinja_filter for python unsure how would implament that in this context as not really filtering said list just trying to compress it. The issue why cannot have multiple lines is attempting to follow an intent/actual compare and using multiple lines or incorrect , that dont exactly match will result in mismatches on every port during compares. |
Beta Was this translation helpful? Give feedback.
I was talking with someone else and confirmed Jinja does not store variables globally by default. this was the issue that was happening. This required using namespaces.
once edited vars to use ns.name the items stuck the way i was expecting.
{%- set ns = namespace(ranges=[], start=vlan_list[0], end=vlan_list[0]) %}
cleaned up code that will keep var in loops: