Logo Netbox Config Templates

Netbox Config Templates

Tổ chức
netboxlabs
netbox-config-templates

How to use NetBox's configuration template system for generating device configs. Covers Jinja2 templates, config contexts, template rendering API, and common patterns. Use when building config generation workflows, automating device provisioning, or integrating NetBox with config management tools.

Tổng quan

Nhà phát hànhnetboxlabs
Kho mãskills
Tên kỹ năngnetbox-config-templates
Sao
21
Bản fork
4
Tệp đi kèm
3
Giấy phépApache-2.0
Liên kết
  • Hướng dẫn bằng Markdown

    Tệp SKILL.md được mô hình tải khi cần, nên chỉ tốn token khi có yêu cầu thực sự phù hợp.

  • Dùng được với mọi LLM

    Kỹ năng AI dùng hướng dẫn viết bằng Markdown thay vì mã dành riêng cho một nhà cung cấp, nên dùng được với GPT, Claude, Gemini, Grok hoặc mô hình cục bộ.

  • 3 tệp đi kèm

    Các tập lệnh, mẫu và tài liệu tham khảo mà mô hình có thể đọc khi làm việc. Các tệp chỉ cho phép đọc và không bao giờ được thực thi.

  • Mã nguồn mở

    Được netboxlabs công bố trên GitHub. Hãy đọc các tệp nguồn trước khi cài đặt.

Cài đặt

Cài đặt kỹ năng AI Netbox Config Templates trong TypingMind để dùng với bất kỳ LLM nào, hoặc thêm vào một tác nhân AI khác có thể đọc SKILL.md.

1

Cài đặt trong TypingMind

TypingMind cài đặt kỹ năng trực tiếp từ thư mục GitHub — đọc SKILL.md, đóng gói các tệp tài nguyên và lưu kết quả trên máy.

  1. Mở ứng dụng và vào Plugin → Kỹ năng.
  2. Chọn "Cài đặt từ GitHub".
  3. Dán URL của thư mục kỹ năng được hiển thị bên dưới rồi xác nhận.
    https://github.com/netboxlabs/skills/tree/main/skills/netbox-config-templates
  4. Bật kỹ năng trong từng cuộc trò chuyện mà bạn muốn sử dụng kỹ năng đó.
Plugin → Kỹ năng → Thêm kỹ năng → Từ URL GitHub, sau đó dán URL thư mục và nhấn Tiếp tục.
2

Cài đặt trong tác nhân AI khác

Bất kỳ tác nhân AI nào đọc được định dạng Agent Skills đều có thể dùng kỹ năng này — hãy sao chép thư mục vào thư mục kỹ năng của tác nhân AI đó.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/netboxlabs/skills.git /tmp/skills
mkdir -p .claude/skills
cp -r /tmp/skills/skills/netbox-config-templates .claude/skills/netbox-config-templates
Khởi động lại Claude Code sau khi sao chép để ứng dụng nhận kỹ năng mới.

Sử dụng trong TypingMind

Bật Netbox Config Templates trong bất kỳ cuộc trò chuyện nào trên TypingMind, mô hình sẽ tự xử lý phần còn lại. Tên và mô tả của kỹ năng nằm trong prompt hệ thống. Ngay khi có yêu cầu phù hợp, mô hình tự tải toàn bộ hướng dẫn — bạn không cần gọi thủ công và kỹ năng không tốn token cho đến khi thực sự được dùng.

Mô hình tự nạp Netbox Config Templates ngay khi có yêu cầu phù hợp.

Dùng được với mọi mô hình AI

Kỹ năng AI là các hướng dẫn Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên bạn có thể dùng Netbox Config Templates với cả những mô hình khác ngoài mô hình ban đầu. Chỉ cần cài đặt một lần trong TypingMind rồi dùng với GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama hoặc mô hình cục bộ do bạn tự chạy — tất cả đều dùng khóa API của riêng bạn.

  • Chỉ tải khi cần

    Prompt hệ thống chỉ chứa tên và mô tả. Hướng dẫn được tải khi có yêu cầu phù hợp đầu tiên, nên khi kỹ năng chưa được dùng, bạn không tốn token cho phần hướng dẫn.

  • Đổi mô hình ngay trong cuộc trò chuyện

    Vì kỹ năng là hướng dẫn chứ không phải mã, việc đổi mô hình không làm kỹ năng ngừng hoạt động — mô hình tiếp theo vẫn đọc cùng tệp SKILL.md.

Hướng dẫn của kỹ năng

Đây là nội dung SKILL.md mà mô hình tải. Hãy đọc trước khi cài đặt — kỹ năng là những hướng dẫn mà mô hình của bạn sẽ làm theo.

NetBox Config Templates

Your knowledge of NetBox config templates may be outdated. Template context variables, rendering API, and config context merge behavior evolve between releases. Prefer retrieval over pre-trained knowledge.

Retrieval Sources

SourceURL / MethodUse for
Config templates docshttps://netboxlabs.com/docs/netbox/features/configuration-rendering/Template syntax, context variables
Config contexts docshttps://netboxlabs.com/docs/netbox/features/context-data/Hierarchical data, merge rules
NetBox repohttps://github.com/netbox-community/netboxTemplate rendering source code
NetBox MCP serverIf configured — fetch device config contexts to test template renderingVerify context data

NetBox provides a built-in Jinja2-based configuration rendering system. You define templates, populate data through config contexts, and render per-device or per-VM configurations via the API. This skill covers the entire workflow.

When to Use This Skill

  • Generating device/VM configurations from NetBox data
  • Setting up config contexts (hierarchical data) for template rendering
  • Integrating NetBox config rendering into CI/CD or provisioning pipelines
  • Troubleshooting template rendering issues or config context merge behavior

Quick Reference

Template Resolution Order (Device)

device.config_template → device.role.config_template → device.platform.config_template

First match wins. Only one template renders per device. VMs follow the same pattern (role → platform).

Key API Endpoints

ActionMethodEndpoint
Render device configPOST/api/dcim/devices/{id}/render-config/
Render VM configPOST/api/virtualization/virtual-machines/{id}/render-config/
Render template directlyPOST/api/extras/config-templates/{id}/render/
CRUD config templatesGET/POST/PUT/PATCH/DELETE/api/extras/config-templates/
CRUD config contextsGET/POST/PUT/PATCH/DELETE/api/extras/config-contexts/

Context Variables Cheat Sheet

In device/VM rendering (render-config):

VariableTypeDescription
device / virtualmachineORM instanceFull model with all relations
(config context keys)variesMerged config context data as top-level keys
(POST body keys)variesExtra data sent with the render request

In general-purpose rendering (config-templates/{id}/render/):

VariableTypeDescription
dcim, ipam, virtualization, etc.module-likeAccess to all public NetBox model classes
(POST body keys)variesExtra data sent with the render request

See references/context-variables.md for the complete breakdown.

Config Context System

Config contexts provide structured JSON data to templates. They are assigned based on object attributes and merged by weight.

Assignment Logic

A config context applies when the object matches all non-empty assignment categories (AND across categories) and any value within each category (OR within a category).

Assignment categories: Regions, Site groups, Sites, Locations, Device types, Roles, Platforms, Cluster types, Cluster groups, Clusters, Tenant groups, Tenants, Tags.

Merge Order

  1. All matching active config contexts, ordered by weight ascending, then name
  2. Higher-weight contexts overwrite lower-weight on key collision
  3. Local context data (on the device/VM itself) merges last and always wins

⚠️ Lists Are Replaced, Not Merged

deepmerge() merges dicts recursively but replaces non-dict values entirely:

json
// Weight 100: {"ntp_servers": ["10.0.0.1", "10.0.0.2"]}
// Weight 200: {"ntp_servers": ["10.1.1.1"]}
// Result:     {"ntp_servers": ["10.1.1.1"]}  ← NOT concatenated

Design data structures with this in mind. Use dicts with unique keys when you need additive merging.

Hierarchy Resolution

For hierarchical models (Region, Site Group, etc.), a context assigned to a parent also applies to all descendants. A context assigned to "Americas" region matches devices in "US-East" sub-region.

Pre-Rendered Cache (NetBox 4.7+)

On 4.7 the merged result is pre-rendered and cached on each device/VM. Any upstream change (a config context created/edited/deleted, or a device/VM attribute that affects which contexts apply) invalidates the cache and a non-blocking background job re-renders it; in the window between the two, reads fall back to on-demand rendering, so results are never stale. Merge semantics are unchanged. After upgrading, the upgrade script runs manage.py rebuild_config_context_cache (one UPDATE per device/VM; safe to interrupt and re-run). Bulk writes that bypass signals (queryset.update()) do not invalidate the cache — run rebuild_config_context_cache --force afterwards. On 4.5/4.6 config context is computed on every read.

For a deep dive on merging, see references/config-context-merging.md. For config context data modeling best practices, see netbox-data-modeling.

Writing Templates

Accessing Device Data

The device (or virtualmachine) variable is a full Django ORM instance:

jinja2
hostname {{ device.name }}
!
{% if device.primary_ip4 %}
ip address {{ device.primary_ip4.address | ipaddr('address') }}
{% endif %}
!
{% for iface in device.interfaces.all() %}
interface {{ iface.name }}
  description {{ iface.description | default('', true) }}
  {% for ip in iface.ip_addresses.all() %}
  ip address {{ ip.address }}
  {% endfor %}
{% endfor %}

Using Config Context Data

Config context keys appear as top-level template variables:

jinja2
{% for server in ntp_servers | default([]) %}
ntp server {{ server }}
{% endfor %}
!
{% for server in syslog_servers | default([]) %}
logging host {{ server }}
{% endfor %}
!
{% if snmp_community is defined %}
snmp-server community {{ snmp_community }} RO
{% endif %}

Template Inheritance (DataSource Required)

{% extends %} and {% include %} only work when templates are stored in a DataSource (git repo, S3, etc.). Templates defined with inline template_code cannot resolve other templates.

jinja2
{# Stored in a DataSource alongside base.j2 #}
{% extends 'base.j2' %}

{% block interfaces %}
{% for iface in device.interfaces.all() %}
interface {{ iface.name }}
{% endfor %}
{% endblock %}

ORM Queries in Templates

Both device and general-purpose rendering expose NetBox models:

jinja2
{# Query prefixes from IPAM #}
{% set mgmt_prefixes = ipam.Prefix.objects.filter(role__slug='management') %}
{% for pfx in mgmt_prefixes %}
ip route {{ pfx.prefix }} Management
{% endfor %}

Warning: ORM queries run unsandboxed against the database. A careless .all() on a large table will be slow. There is no query limiting.

Jinja2 Environment

  • Templates run in a SandboxedEnvironment — no file I/O, no arbitrary imports
  • Custom filters can be added in NetBox configuration via JINJA_FILTERS (4.7+; the old name JINJA2_FILTERS still works but is deprecated and removed in 5.0) / JINJA2_FILTERS (4.5/4.6). Filter precedence on 4.7, lowest to highest: built-in (env) → plugin-registered → instance JINJA_FILTERS.
  • Plugins can register Jinja filters and inject template context variables (NetBox 4.7+) via jinja_env.py / register_jinja_filters() and PluginConfig.get_jinja_context() — see netbox-plugin-development for the how-to. Plugin context is global (not per-object) and must not reuse app-label names like dcim.
  • Custom Objects in templates (NetBox 4.7+, netbox-custom-objects v0.6.1+): custom_objects.<type_name>.filter(device=device) or '<type_name>' | custom_objects exposes custom object types by internal name; on 4.5/4.6 custom_objects is simply absent. See netbox-custom-objects.
  • Built-in env() filter (NetBox 4.6.2+) — returns a system environment variable's value: {{ 'WEBHOOK_TOKEN_3' | env }}. Gated by the JINJA_ENVIRONMENT_PARAMS config list (an fnmatch wildcard allowlist of permitted variable names); returns None for any name not matched. On 4.6.1 and earlier there are no built-in custom filters — only standard Jinja2 filters.
  • Per-template environment_params can customize behavior (e.g., undefined: jinja2.StrictUndefined), but on NetBox 4.6.1+ the keys are allowlisted — see below.

NetBox 4.6.1+ — environment_params allowlist (CVE-2026-29514). A patched RCE via environment_params (shared by ConfigTemplate and ExportTemplate) restricts which keys are accepted (JINJA_ENV_PARAMS_ALLOWED). Allowed: the standard delimiter/whitespace/scalar params (trim_blocks, lstrip_blocks, autoescape, keep_trailing_newline, block/comment/variable *_string delimiters, etc.) and undefined — but undefined must be one of jinja2.StrictUndefined, jinja2.Undefined, jinja2.ChainableUndefined, jinja2.DebugUndefined. extensions, finalize, loader, and bytecode_cache are blocked and a template setting them is rejected. The skill's examples (StrictUndefined, trim_blocks, lstrip_blocks) remain valid; do not recommend the blocked keys.

Common Vendor Patterns

Strategy 1: Platform-Based Template Assignment (Recommended)

Assign different config templates to different Platforms:

PlatformConfig Template
junosjunos-base.j2
ios-xeios-xe-base.j2
eoseos-base.j2

Template resolves via: device → role → platform. This is the cleanest approach.

Strategy 2: Conditional Logic in a Single Template

jinja2
{% if device.platform.slug == 'junos' %}
system {
    host-name {{ device.name }};
}
{% elif device.platform.slug == 'ios-xe' %}
hostname {{ device.name }}
{% elif device.platform.slug == 'eos' %}
hostname {{ device.name }}
{% endif %}

Works for small differences but becomes unwieldy. Prefer Strategy 1 for production.

API Rendering Patterns

Render a Device Config

python
import requests

NETBOX = "https://netbox.example.com"
TOKEN = "nbt_abc123.xxxxxxxxxxxxxxxx"
headers = {"Authorization": f"Bearer {TOKEN}"}

# Render config for device ID 42
response = requests.post(
    f"{NETBOX}/api/dcim/devices/42/render-config/",
    headers=headers,
    json={},  # optional extra context data
)
response.raise_for_status()
config = response.json()["content"]

Use Accept: text/plain header to get raw config output without JSON wrapping.

Override Config Context at Render Time

python
# POST body merges after config context (overrides on collision)
response = requests.post(
    f"{NETBOX}/api/dcim/devices/42/render-config/",
    headers=headers,
    json={"ntp_servers": ["10.99.99.1"]},  # overrides config context
)

Render a Template Directly (No Device)

python
# General-purpose rendering — no device/VM in context
response = requests.post(
    f"{NETBOX}/api/extras/config-templates/5/render/",
    headers=headers,
    json={"hostname": "switch01", "vlans": [10, 20, 30]},
)

For detailed API examples including pynetbox and error handling, see references/api-rendering-patterns.md.

Pitfalls

Performance

  • Config context on list endpoints:
    • NetBox 4.7+: merged config context is pre-rendered and cached on each device/VM; ?exclude=config_context is silently ignored on every 4.7.x (harmless if a shared client still sends it). On 4.7.0–4.7.2 it is always loaded and list calls are cheap — the cost moved to a background re-render job. On 4.7.3+ ?omit=config_context (or ?fields=/?brief=True) skips the DB annotation and cached column again — send it when you don't need the context.
    • NetBox 4.5/4.6: computing merged config context per device is expensive — always send GET /api/dcim/devices/?omit=config_context (4.5.2+; ?exclude= is equivalent there) on bulk queries when you don't need it.
  • ORM queries in templates have no guardrails — avoid unbounded .all() on large tables.

Template Behavior

  • Template resolution is first-match only — device → role → platform. A device still has one assigned template. NetBox 4.6+ lets you render any other template against a device's context without changing assignments by passing config_template_id in the render-config request body (or ?config_template_id=<id> on the UI render URL) — useful for CI/dry-run rendering of alternative templates. (Requires view permission on Config Template plus render_config on the device.)
  • No template versioning — templates are mutable. Only NetBox's change log provides history.
  • Render debugging (NetBox 4.6+) — when developing templates in a script/plugin, call render_jinja2(..., debug=True) to enable Jinja2's debug extension ({% debug %}) for inspecting the available context.
  • extends/include requires DataSource — inline template_code cannot reference other templates.

Config Context Surprises

  • Lists replace, don't append — the most common surprise. See merge rules above.
  • POST data silently overrides config context — intentional but can be confusing when debugging unexpected values.
  • environment_params vary per template — undefined variable handling may differ between templates if configured differently.

Version Notes

NetBox 4.7 (2026-09-02)

  • Config context pre-rendered and cached per device/VM, invalidated on upstream changes and re-rendered by a background job (on-demand fallback in between). ?exclude=config_context is silently ignored on every 4.7.x; config_context is always loaded on 4.7.0–4.7.2, while 4.7.3+ skips the DB annotation again when ?omit=config_context/?fields=/?brief=True leaves it out. DeviceWithConfigContextSerializer/VirtualMachineWithConfigContextSerializer merged into the base serializers. Upgrade runs rebuild_config_context_cache.
  • JINJA2_FILTERS renamed JINJA_FILTERS (old name accepted with a deprecation warning until 5.0).
  • Plugins can register Jinja filters and inject context variables (jinja_env.py, register_jinja_filters(), get_jinja_context()); precedence built-in → plugin → instance JINJA_FILTERS. netbox-custom-objects v0.6.1+ uses this to expose custom_objects.<type> / '<type>' | custom_objects.
  • New data reachable from templates: device.cooling_method, interface channels/channel_id (channelized subinterfaces of type channel), service port_mappings (list of "tcp/80" strings; protocol/ports deprecated), device_type.end_of_life. Selection custom fields still read as raw values via device.cf / custom_field_data in templates — only the REST/GraphQL representation became {value, label}.
  • Platform: PostgreSQL 15+, Redis 6.0+, ltree extension; recommend 4.7.3+ (4.7.0/4.7.1 leaked token plaintexts into job results; 4.7.3 adds branch-safe background writes and the config-context omit optimisation).

NetBox 4.6 (2026-05-05)

  • config_template_id override on render-config (4.6.0); render_jinja2(..., debug=True) (4.6.0); environment_params allowlist (4.6.1, CVE-2026-29514); built-in env filter gated by JINJA_ENVIRONMENT_PARAMS (4.6.2); autoescaping explicitly disabled for config templates rendered via SandboxedEnvironment (4.6.5).

References

Tệp đi kèm

Khi kỹ năng đã được tải, mô hình có thể đọc các tệp này nếu cần. Các tệp này chỉ dùng để đọc và không bao giờ được thực thi.

Câu hỏi thường gặp

Kỹ năng AI Netbox Config Templates làm được gì?

How to use NetBox's configuration template system for generating device configs. Covers Jinja2 templates, config contexts, template rendering API, and common patterns. Use when building config generation workflows, automating device provisioning, or integrating NetBox with config management tools.

Vì sao nên dùng Netbox Config Templates trên TypingMind?

Vì bạn chỉ cần cài một lần rồi dùng với bất kỳ mô hình nào. Netbox Config Templates là nội dung Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên cùng một kỹ năng có thể chạy trên GPT-5, Claude, Gemini, Grok hoặc mô hình trên thiết bị — và bạn có thể đổi mô hình ngay trong cuộc trò chuyện mà kỹ năng vẫn hoạt động. TypingMind dùng khóa API riêng của bạn, nên bạn thanh toán trực tiếp cho nhà cung cấp thay vì trả phí thuê bao theo suất người dùng, đồng thời kỹ năng và các cuộc trò chuyện vẫn nằm trong bộ lưu trữ của bạn.

Làm thế nào để cài Netbox Config Templates trong TypingMind?

Mở Plugin → Kỹ năng → Cài đặt từ GitHub trong TypingMind rồi dán https://github.com/netboxlabs/skills/tree/main/skills/netbox-config-templates. TypingMind đọc tệp SKILL.md, đóng gói các tệp đi kèm rồi cài đặt cả gói dưới dạng một kỹ năng mà bạn có thể bật cho từng cuộc trò chuyện.

Những mô hình AI nào có thể dùng Netbox Config Templates?

Bất kỳ mô hình nào bạn kết nối trong TypingMind. Kỹ năng AI là các hướng dẫn bằng Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên GPT, Claude, Gemini, Grok và các mô hình chạy trên thiết bị đều có thể tải kỹ năng này khi có yêu cầu phù hợp.

Có thể dùng Netbox Config Templates với bao nhiêu mô hình AI?

Bao nhiêu cũng được. Miễn là mô hình hỗ trợ kỹ năng, bạn có thể dùng Netbox Config Templates với mô hình đó — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama và nhiều mô hình khác — tất cả đều trên TypingMind với khóa API riêng của bạn.

Kỹ năng AI Netbox Config Templates có miễn phí không?

Có. Kỹ năng này được netboxlabs phát hành trên GitHub theo giấy phép Apache-2.0. Bạn chỉ trả tiền cho nhà cung cấp AI của mình theo số token đã dùng.

Kỹ năng AI là gì?

Kỹ năng AI là một gói hướng dẫn có thể tái sử dụng, chỉ cho mô hình AI cách thực hiện một tác vụ cụ thể. Kỹ năng tuân theo định dạng mở Agent Skills: một tệp SKILL.md chứa tên và mô tả, cùng các tập lệnh, mẫu hoặc tệp tham khảo mà mô hình có thể cần. Mô hình chỉ đọc hướng dẫn khi yêu cầu của bạn phù hợp với kỹ năng, nên kỹ năng đã cài đặt không phát sinh chi phí cho đến khi được sử dụng.

Kỹ năng AI khác gì với plugin hoặc máy chủ MCP?

Plugin hoặc máy chủ MCP cung cấp các công cụ mới mà mô hình có thể gọi. Khi mô hình gọi một công cụ, mã của công cụ đó chạy ở đâu đó và trả về kết quả. Còn kỹ năng AI cung cấp kiến thức và quy trình: cách tiếp cận tác vụ, các bước cần thực hiện và những tiêu chí mà kết quả cần đáp ứng. Kỹ năng chỉ là nội dung Markdown, nên không cần máy chủ, khóa API hay môi trường thực thi và hoạt động với mọi mô hình.

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇