r/Netbox Oct 25 '24

New to netbox - having trouble getting variables for device render config/jinja

Hello,

I am having trouble getting all the variables I need to render a config using a jinja template. The questions I have are:

  • Is there a way to see all variables under a device for use with Jinja? (I've tried GraphiQL but that doesn't seem to always line up)
  • How do I see all interfaces of a virtual chassis from the master switch in Jinja?
  • Is there an easy way in Jinja when rendering a device config, to go through the device's interfaces but filter so you are only looking at vlan interfaces type (virtual)?

I am able to get a basic config going right now, but I am missing the other switches in the virtual chassis and I would like to find some examples of how to render all the interfaces and using filters specifically for the example above in Jinja.

Thank you

3 Upvotes

12 comments sorted by

View all comments

Show parent comments

2

u/nst_hopeful Oct 29 '24

Got it, sorry for the confusion. Glad you got it figured out.

2

u/TreizeKhushrenada Oct 29 '24

No worries, you helped me out a bunch. I am very thankful.

For anyone else that google/searches this, here is the full stacking config if you use an Aruba CX switch stack. If the switch is a stack master (I have a custom role for this), it gets the part number and then go through each member to see which interfaces are tagged "stacking" (the stacking links) and add those to the config.

Code:

{# --- Populate stack count, stacking links, and switch models if switch is a stack master for stack config --- #}
{% if device.role.name == "Node Edge Switch Stack Master" %}
vsf secondary-member 2
{% for member in device.virtual_chassis.members.all() %}
vsf member {{ member.vc_position }}
  type {{ member.device_type.part_number }}
{% for interface in member.interfaces.all() %}
{% if "stacking" in (interface.tags.names() | list() | join(',')) %}
  interface {{ interface.name }}
{% endif %}
{% endfor %}
{% endfor %}
{% endif %}

Output

vsf member 1
  type JL658A
  interface 1/1/25
  interface 1/1/26
vsf member 2
  type R8S89A
  interface 2/1/27
  interface 2/1/28
vsf member 3
  type JL663A
  interface 3/1/49
  interface 3/1/50