Unable to get custom field value of interface in config template. #21626
-
|
Upfront, my apologies, as this is probably a basic question but I'm unable to find the answer in the discussions, on google or in any documentation. I'm dipping my toes in Netbox and learning on a daily basis :-). I'm modeling our firewall setup to possibly migrate to netbox as a replacement of a home-build tool. With the setup we want to use netbox to create a import file that we use to import to our firewall manager setup. This import is a CSV file and the configuration build logic is in the firewall manager. In the export i need information for our WAN internet connections to represent the IP address assignment type of static, dhcp or PPPOE. I have created a custom selection field under the interface to set the correct value. I'm now trying to get that information imported in the config template value, but whatever i try to do, the custom field data in an interface attached to a device will not show. It looks to me like the config template context in Netbox can't access the custom field or custom field data during the config template rendering. The Jinja code i'm trying to use looks something like this: This results in the output below: There is no error in the jinja template when running it, but i can't get the custom field data. Hopefully someone can point me in the right direction to get these values. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
I created a netbox shell tutorial a couple years back. Here you can see how I call custom fields in a jinja2 template
Good luck! |
Beta Was this translation helpful? Give feedback.
-
|
Yeah, I just figured it out before your post @duanenoland-stack. You need to use the .cf. value instead of iface.custom_fields.get("wan_address_type"). This is also listed in the documentation: https://netboxlabs.com/docs/netbox/customization/custom-fields/ but easy to overlook :-). Thanks for the tutorial, I will have a look at it. For now this is what I need 👍. |
Beta Was this translation helpful? Give feedback.

I created a netbox shell tutorial a couple years back.
https://github.com/bitcollector1/netbox_shell/blob/main/Django_NetBox_Shell.ipynb
Here you can see how I call custom fields in a jinja2 template
https://technobabble.us.to/?p=3415
Good luck!