Skip to content

Rendered config , jinja not fully setting values in loops #17998

Discussion options

You must be logged in to vote

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:

{% for interface in device.interfaces.all() %}
{% if interface.mgmt_only == false %}
interface {{ interface.name }}
{%- if interface.enabled == false %}
 shutdown
{%- elif interface.enabled == true %}
 no shutdown
{%- endif -%}
{%- if interface.mode == "access" -%}
 switchport mode access
 switchport access vlan {{ interface.untagge…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@pl0xym0r
Comment options

@NetworkHow
Comment options

Answer selected by NetworkHow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants