Use this when generating configuration from templates and variables.
Templates
Templates in automation generate configuration files, device configs or messages from a template plus variables, typically with Jinja2, so one tested pattern produces many consistent outputs.
1. Templates generate configs from data (Jinja2, Go templates, Helm).
2. Separate data from logic.
3. Validate rendered output.
4. Keep logic simple.
5. Test rendering.
data + template → render → validate → deploy
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Verification path Verify boundary
Record template revision/path, render run ID and context/object identifiers; inspect the runtime/control-plane result; then query the rendered configuration/document consumed by a downstream parser or service through an independent read path and compare it with the versioned intent. The negative fixture should deliberately exercise risks such as undefined values, unsafe escaping, implicit type conversion, environment-specific filters, secret exposure, whitespace-sensitive syntax and valid render producing invalid target configuration, choosing the cases most relevant to vSphere template identity/version, guest customization, clone task, datastore/network placement and post-clone VM/guest verification. For Automation → Templates, the evidence must connect the control-plane result to the rendered configuration/document consumed by a downstream parser or service and explain any gap between desired, controller-reported and consumer-visible state.
Step 2 Where it fails Narrow the fault
Failure analysis for Automation → Templates should follow the path through the components: template/context → expression evaluation → filters/tests → rendering/escaping → target parser → target apply → read-back. Common failure classes include undefined values, unsafe escaping, implicit type conversion, environment-specific filters, secret exposure, whitespace-sensitive syntax and valid render producing invalid target configuration. Before retrying a mutating operation, read current target state using the stable identity template revision/path, render run ID and context/object identifiers; if state is unknown, stop broad retries.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
Subtopics
Go one level deeper into this subject.
Template fundamentals: separate the structure (template) from the data (variables), keep templates small and readable, and test the rendered output before deploying it.
Subtopic Jinja2Jinja2 is the Python template engine used by Ansible, Salt, NetBox and Nornir, with {{ variables }}, {% if %} and {% for %} blocks, filters and macros.
Subtopic VariablesTemplate variables are the values inserted into templates, coming from inventory, a source of truth or files.
Subtopic ConditionsConditions in templates include or change output based on variables, such as {% if vlan_id %} ...
Subtopic LoopsLoops in templates repeat a block for each item, such as {% for intf in interfaces %} to generate interface sections, keeping templates short for many items.
Subtopic FiltersTemplate filters transform values during rendering, such as {{ name | upper }}, {{ list | join(',') }} or ipaddr filters for subnets in Ansible.
Subtopic Configuration TemplatesConfiguration templates generate full device or service configs, such as a switch config or nginx.conf, from a base template plus per-device variables.
Subtopic Golden ConfigurationsGolden configurations are the approved standard configs for each device role, generated from templates and used as the reference for compliance and drift checks.
Subtopic RenderingRendering combines a template with variables to produce the final text, such as Ansible's template module or jinja2's render(), which should fail on undefined variables.
Subtopic ValidationValidation of rendered templates checks the output before deployment, such as nginx -t, a YAML lint, a device config parser or comparing with the golden configuration.
Subtopic Template TroubleshootingTroubleshoot templates by rendering with test data and diffing the output, enabling StrictUndefined to catch missing variables, checking whitespace control and filter usage.
- Separate structure (template) from data (variables).
- Fail on undefined variables.
- Validate rendered output before deploying.
- Template files in git — versioned
python3 -c "import jinja2;print(jinja2.__version__)"— engine- Rendered output validation — correctness
ReferenceWhy it matters1 section · depth on demand
In depth
Templates generate text — configuration files, scripts, reports — by combining a fixed layout with variable data. In automation, Jinja2 is the most common engine (Ansible, Salt, Python), with Go templates in Helm and Terraform's templatefile().
{# chrony.conf.j2 #}
{% for s in ntp_servers %}
server {{ s }} iburst
{% endfor %}
makestep 1.0 3
| Practice | Reason |
|---|---|
| Keep logic minimal in templates | Readability |
| Put data in variables/source of truth | One template, many devices |
| Render and diff in CI | See real changes |
Use StrictUndefined | Fail on missing variables |
ReferenceImportant terms & boundaries1 section · depth on demand
Mechanics
Automation → Templates is owned at runtime by the template engine rendering a versioned template with a bounded context and filter/function set. Its durable intent is template source plus context schema, filters/tests and escaping/output contract; the stable identity contract is template revision/path, render run ID and context/object identifiers. The consumer-visible target is the rendered configuration/document consumed by a downstream parser or service. The operating invariants are that undefined variables are handled intentionally, escaping/quoting matches target syntax, filters are deterministic, secrets are not logged and rendered output is parsed/validated before apply. Follow the chain of components template/context → expression evaluation → filters/tests → rendering/escaping → target parser → target apply → read-back and record which layer currently owns truth.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Templates. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://learn.microsoft.com/en-us/azure/well-architected/operational-excellence/enable-automation · confidence 94%Deep reference
Healthy vs suspicious evidence
Output interpretation
Capture at minimum template revision, context keys, render ID, undefined/error location, output digest/path, target parser result and applied object read-back. For vSphere template identity/version, guest customization, clone task, datastore/network placement and post-clone VM/guest verification, prefer typed fields and stable IDs over human presentation text.