`template` fails with `"msg": "failed to validate"` and `nginx: [emerg] unknown directive "proxy_passs"`
IntermediateTroubleshootingModules, Idempotency and Handlers
Answer
Likely causes → validate: worked as designed: the rendered file failed the config test, so Ansible kept the old file in place. The bug is in the template or its variables.
Diagnose → The stderr in the result shows the validator output. Render the template locally to inspect it.
Fix → Fix the template. Keep the validation in place:
- ansible.builtin.template:
src: nginx.conf.j2
dest: /etc/nginx/nginx.conf
validate: nginx -t -c %s
notify: Reload nginx
For included snippets that cannot be tested alone, validate the whole config in a separate command: nginx -t before the handler runs.
Prevent → Use validate on every config file that has a checker: sshd -t -f %s, visudo -cf %s, nginx -t, haproxy -c -f %s.
More on Modules, Idempotency and Handlers
`ERROR! The requested handler 'Restart nginx' was not found in either the main handlers list nor in the listening handlers list`BeginnerA handler named `restart {{ app_service }}` is never found when notified as `restart myapp`AdvancedA `command` task reports `changed` on every run, and the Molecule idempotence check failsBeginner`curl ... | tar xz` fails on the host but the `shell` task reports successIntermediate`lineinfile` appends the same line again on every runIntermediate`lineinfile` with `backrefs: true` reports `ok` but the line was never addedIntermediate