Add arbitrary queries to jinja2 templates #8807

Closed
opened 2025-12-29 20:41:30 +01:00 by adam · 1 comment
Owner

Originally created by @chris240189 on GitHub (Nov 3, 2023).

NetBox version

v.3.6.4

Feature type

Change to existing functionality

Proposed functionality

As of now when using jinja2 config templates as far as i know it's only possible to use data, that is somehow related to the devices entity it belongs.
Going through the documentation and discussions (especially https://github.com/netbox-community/netbox/discussions/12568) helped a lot.

What I didn't find yet, is how to query data, that is not directly linked to a device.

I triet starting a discussion, but didn't get any reponse there.
https://github.com/netbox-community/netbox/discussions/14074

Use case

When templating VLANs, the way that is proposed often is going via the site. like so:
{% for vl in device.site.vlans.all() %} vlan {{vl.vid }} name {{ vl.name }} {%- endfor %}

However this only includes VLANs related to the site and is not including any global VLANs.

Database changes

No response

External dependencies

No response

Originally created by @chris240189 on GitHub (Nov 3, 2023). ### NetBox version v.3.6.4 ### Feature type Change to existing functionality ### Proposed functionality As of now when using jinja2 config templates as far as i know it's only possible to use data, that is somehow related to the devices entity it belongs. Going through the documentation and discussions (especially https://github.com/netbox-community/netbox/discussions/12568) helped a lot. What I didn't find yet, is how to query data, that is not directly linked to a device. I triet starting a discussion, but didn't get any reponse there. https://github.com/netbox-community/netbox/discussions/14074 ### Use case When templating VLANs, the way that is proposed often is going via the site. like so: `{% for vl in device.site.vlans.all() %} vlan {{vl.vid }} name {{ vl.name }} {%- endfor %}` However this only includes VLANs related to the site and is not including any global VLANs. ### Database changes _No response_ ### External dependencies _No response_
adam added the type: featurestatus: duplicate labels 2025-12-29 20:41:30 +01:00
adam closed this issue 2025-12-29 20:41:30 +01:00
Author
Owner

@jeremystretch commented on GitHub (Nov 3, 2023):

The ability to directly reference other NetBox models within ConfigTemplates was added in v3.6.0. Please see #12814.

@jeremystretch commented on GitHub (Nov 3, 2023): The ability to directly reference other NetBox models within ConfigTemplates was added in v3.6.0. Please see #12814.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#8807