Pcornel
Automation · Templates

Template Troubleshooting

Cheat sheet · https://pcornel.dk/topic.php?topic=5816

Back to the Topic

Answer

Troubleshoot templates by rendering with test data and diffing the output, enabling StrictUndefined to catch missing variables, checking whitespace control and filter usage.

Remember

  • Undefined variables are the most common problem.
  • Whitespace can break formats.
  • Filters may behave unexpectedly.

First checks

  • python3 -c "from jinja2 import Environment,StrictUndefined" + render with sample — reproduce
  • ansible <host> -m debug -a 'var=<variable>' — inspect variable
  • Whitespace/indentation in output — formatting

Commands

python -c "from jinja2 import Environment; Environment().parse(open('<template.j2>').read())"
Read-only/validation observation for whether the selected Jinja2 template parses successfully.

Verify in this order

data + template → error → fix

Where it usually breaks

Input/desired state → request accepted → job/task terminal status → target object read-back → effective runtime state → original workload → regression/rollback readiness.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5816

Confirmation

Confirm action

Continue?