Referencing config-templates defined in provisioning -> config-templates from other config-templates #15505
-
Can someone please let me know how to reference a config-template (e.g.: cisco-ios-base, cisco-ios-snmp, cisco-ios-tacacs, etc) from within another? E.g. if I have multiple config templates that I use to build a 'main' config template. e.g. the main config-template 'cisco-ios' contains multiple smaller config-templates usually imported using {{ import XXXX }}? Is this even possible? When using: {{ import cisco-ios-base}} or other existing config-templates, it spits out a TemplateNotFound error. Is there a special way to reference templates configured within Netbox? I don't really want to use the local disk method (putting files on a file system) as we would like regular users to be able to edit this from within netbox (Provisioning -> Config-Templates) instead of having to have them SSH/SFTP files! Is this possible? If not, I think this would be a great feature. I've noticed This issue where Jeremy mentions "It is already possible to reference other templates from within the same data source using the standard Jinja2 {% include %} tag. Please open a discussion if you need assistance utilizing this feature." - What 'data-source' do I specify when I want to reference config-templates from within netbox (defined in Provisioning -> Config Templates)? I'm using Netbox v3.7.3. Thanks, Frank |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
I use personnaly git as data source + "master" template at root of path, various sub folders and jinja in them. check #14348 |
Beta Was this translation helpful? Give feedback.
-
Thanks pl0xym0r, but the goal is not to use the file structure. Is there no way to use the config-templates defined in netbox itself? It would be much easier to have users define config-templates in netbox itself (without using the traditional directory structure). If it is all done in Netbox, then you don't have to worry about maintaining folder structure / using git / etc. It would be great to just have users use netbox for everything, instead of now having to provide SSH access, use git to manage files, etc. I think if this is not possible then this is a missed opportunity. It would be great if there was a 'special' folder that would instruct netbox to use the 'internal' templates (ie. templates defined in netbox, not in some directory path). What I have at the moment is lots of config-templates for different components of the config and want to have another config-template to include the others, e.g.: in 'Propvisioning -> Config Templates' I have 4 config-templates defined: cisco-ios-base What I want to do is add another config-template called 'cisco-ios', which has includes to these other 4, e.g.: {% include cisco-ios-base %} What I am trying to find out is how do I reference internal config templates (not on disk, but defined in netbox). If this is not possible, then I will request it as a feature. I think the more our users can do in netbox, the better. Most teams already use so many tools - and seems like it can't be too complex for the devs to add this feature. Thanks! |
Beta Was this translation helpful? Give feedback.
-
I think it was not designed to do this, as you are trying to including into a jinja template a netbox object. |
Beta Was this translation helpful? Give feedback.
I think it was not designed to do this, as you are trying to including into a jinja template a netbox object.
You can use stuff like {{ extras.ConfigTemplate.objects.get(name="cisco-ios-base").template_code }} to access the str of the others config template but it's not rendered (twice) by python.