From 98fec937b860325cff1e1bbc6fa633b366732c55 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Fri, 17 Feb 2023 08:31:30 -0500 Subject: [PATCH] Add feature documentation for config rendering --- docs/features/configuration-rendering.md | 37 +++++++++++++++++++++++- docs/features/context-data.md | 2 ++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/docs/features/configuration-rendering.md b/docs/features/configuration-rendering.md index 0ba798d30..2fe43f046 100644 --- a/docs/features/configuration-rendering.md +++ b/docs/features/configuration-rendering.md @@ -1,3 +1,38 @@ # Configuration Rendering -## TODO +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. + +```mermaid +flowchart TD + ConfigContext & ConfigTemplate --> Config{{Rendered configuration}} + +click ConfigContext "../../models/extras/configcontext/" +click ConfigTemplate "../../models/extras/configtemplate/" +``` + +## Configuration Templates + +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. + +```jinja2 +{% extends 'base.j2' %} + +{% block content %} + system { + host-name {{ device.name }}; + domain-name example.com; + time-zone UTC; + authentication-order [ password radius ]; + ntp { + {% for server in ntp_servers %} + server {{ server }}; + {% endfor %} + } + } + {% for interface in device.interfaces.all() %} + {% include 'common/interface.j2' %} + {% endfor %} +{% endblock %} +``` + +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. diff --git a/docs/features/context-data.md b/docs/features/context-data.md index 04e795fd5..22aeccea2 100644 --- a/docs/features/context-data.md +++ b/docs/features/context-data.md @@ -11,6 +11,8 @@ Configuration context data (or "config contexts" for short) is a powerful featur } ``` +Context data can be consumed by remote API clients, or it can be employed natively to render [configuration templates](./configuration-rendering.md). + Config contexts can be computed for objects based on the following criteria: | Type | Devices | Virtual Machines |