Verifying nginx configurations in ansible

May 23, 2016

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: "/.conf"
    validate: "echo 'http { include \'%s\'; }' > /tmp/n && nginx -t -c /tmp/n"
Verifying NGINX configurations in ansible - May 23, 2016 - mw