Use it when the symptom is “Template Failure”: work through the layers in order and stop at the first one that fails.
Template Failure
Template Failure isolates parsing, variable resolution, filter/function, escaping, whitespace and semantic rendering errors before generated configuration or payload is applied.
1. Template failure: undefined variables, wrong types, filter missing, invalid rendered syntax.
2. Render locally.
3. Strict undefined.
4. Validate output.
5. Add test.
data + template → render error → fix
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
ansible-playbook --syntax-check <playbook.yml>Primary Commands
Configuration and operational commands for this Topic.
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 Operational evidence path Verify boundary
template revision → engine/version → variable precedence/provenance → expression/filter → rendered artifact → syntax/schema validation → semantic diff → apply → target read-back
Healthy evidence: render is reproducible from pinned template/inputs, error location or semantic diff is explicit, validation passes, and target read-back matches intent.
Step 2 Telling causes apart Verify boundary
Known-good is syntax-check exiting 0, the target template rendering successfully for the affected inventory context, and the produced configuration/text matching explicit expected values before deployment. Broken state is a deterministic parser/undefined-variable/type/filter error or syntactically valid output with wrong rendered values. --syntax-check shows playbook syntax only; the limit of what it shows for a template includes runtime variable resolution and inspection of the rendered artifact.
Step 3 Failure modes and next checks Narrow the fault
Suspicious evidence: operators patch generated output manually, variable provenance is unknown, rendered text is deployed without validation, or template engine versions drift.
Step 4 Observation-driven branch and next-check logic Narrow the fault
Run ansible-playbook --syntax-check <playbook.yml> on the same revision. If it fails, correct the reported YAML/play/task syntax first. If it passes but rendering fails, identify the exact template and host, then inspect variable precedence, undefined values, expected data type and filter/plugin availability using the same inventory/context. If only one host fails, compare its host/group variables rather than changing the shared template globally. Preserve the rendered error and variable path before adding defaults that could hide missing data.
Step 5 Common mistakes Narrow the fault
- Undefined variables rendered as empty.
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.
- Template renders ≠ generated output is semantically correct.
- No undefined-variable error ≠ values came from the intended source.
- Valid syntax ≠ safe or intended configuration.
- Rendered diff looks small ≠ blast radius is small.
- Render locally with same data — reproduce
- StrictUndefined errors — missing vars
- Native validator output — syntax
ReferenceWhat it is1 section · depth on demand
Core model
Pin template revision and rendering engine/version; capture effective variable set and undefined behavior safely; render deterministically; validate output syntax/schema and semantic invariants; diff against known/desired output; fix source template or data; rerender and verify target acceptance.
ReferenceHow it works1 section · depth on demand
How it works and how it fails
Template Failure happens before or during rendering when syntax, variable names/types, filters or control structures do not match the templating engine's model. For Ansible, ansible-playbook --syntax-check validates YAML/playbook structure and parsability but does not render every runtime variable path or execute modules. Inventory/group vars, host facts and secrets may therefore fail later even when syntax-check is clean.
ReferenceImportant terms & boundaries2 sections · depth on demand
What this shows and what it does not
Template rendering shows text generation under specific inputs only, but it does not show the artifact is safe, intended or accepted by the target.
Method
Template failures happen when rendering fails (syntax error, undefined variable) or renders wrong output. A systematic method finds the cause quickly.
1. Read the error: template file, line and message.
2. Render the template alone with the same data (ansible -m template in check mode or a small Python script).
3. Inspect the data actually passed: dump variables for the host.
4. Check whitespace control and loops for unexpected output.
5. Diff rendered output against the expected golden file.
| Error | Cause |
|---|---|
'dict object' has no attribute 'x' | Missing key in data |
unexpected end of template | Unclosed {% if %}/{% for %} |
| Extra blank lines/indentation | trim_blocks/lstrip_blocks |
Wrong type output (True vs true) | Python vs target format |
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 Automation Troubleshooting > Template Failure. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://learn.microsoft.com/en-us/azure/architecture/patterns/retry · confidence 94%Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.
Quick lookup tables
Template Failure troubleshooting proof-boundary map
Fast symptom/scope, first-failed-boundary, effective-outcome and recovery/closure map for Template Failure.
| Boundary | Healthy evidence | Suspicious evidence |
|---|---|---|
| Symptom / scope | Time window, immutable source/run identity, effective inputs and exact targets are explicit | Floating source, changed inputs or ambiguous targets destroy reproducibility |
| First failed boundary | Transport/auth/dependency/render/operation evidence identifies the earliest divergence | Investigation starts at the final error and skips earlier unproven boundaries |
| Effective outcome | Controller result is paired with target read-back and workload/service acceptance | Green execution state or changed symptom substitutes for effective-state verification |
| Recovery / closure | Minimal change restores the original test and regression/partial-state checks are clean | Broad retry or unrelated edits make the incident non-reproducible and hide residual state |