You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* WIP
* Add config_template field to Device
* Pre-fetch referenced templates
* Correct up_to_date callable
* Add config_template FK to Device
* Update & merge migrations
* Add config_template FK to Platform
* Add tagging support for ConfigTemplate
* Catch exceptions when rendering device templates in UI
* Refactor ConfigTemplate.render()
* Add support for returning plain text content
* Add ConfigTemplate model documentation
* Add feature documentation for config rendering
One of the critical aspects of operating a network is ensuring that every network node is configured correctly. By leveraging configuration templates and [context data](./context-data.md), NetBox can render complete configuration files for each device on your network.
Configuration templates are written in the [Jinja2 templating language](https://jinja.palletsprojects.com/), and may be automatically populated from remote data sources. Context data is applied to a template during rendering to output a complete configuration file. Below is an example template.
16
+
17
+
```jinja2
18
+
{% extends 'base.j2' %}
19
+
20
+
{% block content %}
21
+
system {
22
+
host-name {{ device.name }};
23
+
domain-name example.com;
24
+
time-zone UTC;
25
+
authentication-order [ password radius ];
26
+
ntp {
27
+
{% for server in ntp_servers %}
28
+
server {{ server }};
29
+
{% endfor %}
30
+
}
31
+
}
32
+
{% for interface in device.interfaces.all() %}
33
+
{% include 'common/interface.j2' %}
34
+
{% endfor %}
35
+
{% endblock %}
36
+
```
37
+
38
+
When rendered for a specific NetBox device, the template's `device` variable will be populated with the device instance, and `ntp_servers` will be pulled from the device's available context data. The resulting output will be a valid configuration segment that can be applied directly to a compatible network device.
Copy file name to clipboardExpand all lines: docs/models/dcim/device.md
+4
Original file line number
Diff line number
Diff line change
@@ -72,6 +72,10 @@ The device's operational status.
72
72
73
73
A device may be associated with a particular [platform](./platform.md) to indicate its operating system. Note that only platforms assigned to the associated manufacturer (or to no manufacturer) will be available for selection.
74
74
75
+
### Configuration Template
76
+
77
+
The [configuration template](../extras/configtemplate.md) from which the configuration for this device can be rendered. If set, this will override any config template referenced by the device's role or platform.
78
+
75
79
### Primary IPv4 & IPv6 Addresses
76
80
77
81
Each device may designate one primary IPv4 address and/or one primary IPv6 address for management purposes.
Copy file name to clipboardExpand all lines: docs/models/dcim/platform.md
+4
Original file line number
Diff line number
Diff line change
@@ -22,6 +22,10 @@ A unique URL-friendly identifier. (This value can be used for filtering.)
22
22
23
23
If designated, this platform will be available for use only to devices assigned to this [manufacturer](./manufacturer.md). This can be handy e.g. for limiting network operating systems to use on hardware produced by the relevant vendor. However, it should not be used when defining general-purpose software platforms.
24
24
25
+
### Configuration Template
26
+
27
+
The default [configuration template](../extras/configtemplate.md) for devices assigned to this platform.
28
+
25
29
### NAPALM Driver
26
30
27
31
The [NAPALM driver](https://napalm.readthedocs.io/en/latest/support/index.html) associated with this platform.
Configuration templates can be used to render [devices](../dcim/device.md) configurations from [context data](../../features/context-data.md). Templates are written in the [Jinja2 language](https://jinja.palletsprojects.com/) and can be associated with devices roles, platforms, and/or individual devices.
4
+
5
+
Context data is made available to [devices](../dcim/device.md) and/or [virtual machines](../virtualization/virtualmachine.md) based on their relationships to other objects in NetBox. For example, context data can be associated only with devices assigned to a particular site, or only to virtual machines in a certain cluster.
6
+
7
+
See the [configuration rendering documentation](../../features/configuration-rendering.md) for more information.
8
+
9
+
## Fields
10
+
11
+
### Name
12
+
13
+
A unique human-friendly name.
14
+
15
+
### Weight
16
+
17
+
A numeric value which influences the order in which context data is merged. Contexts with a lower weight are merged before those with a higher weight.
18
+
19
+
### Data File
20
+
21
+
Template code may optionally be sourced from a remote [data file](../core/datafile.md), which is synchronized from a remote data source. When designating a data file, there is no need to specify template code: It will be populated automatically from the data file.
22
+
23
+
### Template Code
24
+
25
+
Jinja2 template code, if being defined locally rather than replicated from a data file.
26
+
27
+
### Environment Parameters
28
+
29
+
A dictionary of any additional parameters to pass when instantiating the [Jinja2 environment](https://jinja.palletsprojects.com/en/3.1.x/api/#jinja2.Environment). Jinja2 supports various optional parameters which can be used to modify its default behavior.
0 commit comments