Verifying NGINX configurations in ansible

Thou shalt always verify the configurations you produce:

-name: nginx config
  become: yes
  template:
    src: "nginx.conf.j2"
    dest: "/etc/nginx/nginx.conf"
    validate: "nginx -t -c %s"

…even if you’re only creating a partial configuration

- name: Add managed vhost config file (if any vhosts are configured).
  template:
    src: vhost.j2
    dest: "{{ nginx_vhost_path }}/{{ hostname }}.conf"
    validate: "echo 'http { include \'%s\'; }' > /tmp/n && nginx -t -c /tmp/n"