How would you validate Jinja templates without a real server?
BeginnerScenarioPerformance, Testing and CI/CD
Answer
Situation read → Template testing.
What I'd do → Render with ansible localhost -m template or ansible.builtin.template into /tmp in Molecule, then check the output.
ansible localhost -m ansible.builtin.template \
-a "src=templates/app.conf.j2 dest=/tmp/app.conf" -e @tests/vars.yml
Run the target tool's own validator (nginx -t) on the rendered file in Molecule.
Why → You catch undefined variables and syntax early.
Interview tip → Keep test vars files in the role's molecule/ folder.
More on Performance, Testing and CI/CD
A playbook that touches 200 hosts takes 40 minutes. Where do you start tuning?IntermediateYou install 15 packages with a loop and it is slow.BeginnerHow would you test a role in CI before it reaches production?IntermediateWhat would a Molecule `verify.yml` check for an Nginx role?IntermediateMolecule's idempotence step fails. How do you find the offending task?IntermediateDesign a CI pipeline for an Ansible repo.Advanced