Reputation: 16587
When running Ansible in check mode (--check
), it seems the validate
command is not run for template
tasks:
- name: Nginx is configured
template:
src: nginx.conf.j2
dest: /usr/local/etc/nginx/nginx.conf
validate: /usr/local/sbin/nginx -t -c %s
notify: Reload Nginx
Since Ansible is able to tell the difference between the existing destination and new file that is to be installed when running in check mode, it should be able to validate the new file. As it is now, if the template contains an error it will only show up in the real run, not in check mode.
Is there a way to validate template files in check mode?
Upvotes: 2
Views: 3946
Reputation: 33223
I think the thing you're looking for is check_mode: no
which has a very confusing double-negative name but effectively allows a task to opt-out of check-mode suppression.
HOWEVER, in your case you will want to stage that file somewhere first, so you can render the template to disk and have nginx
test it, leaving the mv /tmp/nginx.conf /usr/local/etc/nginx/nginx.conf
and its notify:
guarded by actual check mode.
Upvotes: 2