diff --git a/README.md b/README.md index 0f128b0..0626e9f 100644 --- a/README.md +++ b/README.md @@ -14,10 +14,13 @@ None. Available variables are listed below, along with default values (see `defaults/main.yml`): + nginx_vhost_path: /etc/nginx/sites-enabled + +The path to the vhost configuration folder (where Nginx will look for server configurations). + nginx_remove_default_vhost: false - nginx_default_vhost_path: /etc/nginx/sites-enabled/default -Whether to remove the 'default' virtualhost configuration supplied by Nginx. Useful if you want the base `/` URL to be directed at one of your own virtual hosts configured in a separate .conf file. The `nginx_default_vhost_path` variable defines the path to the default vhosts file. +Whether to remove the 'default' virtualhost configuration supplied by Nginx. Useful if you want the base `/` URL to be directed at one of your own virtual hosts configured in a separate .conf file. nginx_user: "nginx" diff --git a/defaults/main.yml b/defaults/main.yml index 4954679..82ab704 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -5,6 +5,7 @@ nginx_client_max_body_size: "64m" nginx_keepalive_timeout: "65" nginx_remove_default_vhost: false -nginx_default_vhost_path: /etc/nginx/sites-enabled/default +nginx_vhosts: [] +# TODO - add example. nginx_proxy_cache_path: "" diff --git a/tasks/main.yml b/tasks/main.yml index 66ddc0c..d63dbac 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -28,9 +28,4 @@ - name: Ensure nginx is started and enabled to start at boot. service: name=nginx state=started enabled=yes -- name: Remove default nginx config file (if configured). - file: - path: "{{ nginx_default_vhost_path }}" - state: absent - when: nginx_remove_default_vhost - notify: restart nginx \ No newline at end of file +- include: vhosts.yml diff --git a/tasks/vhosts.yml b/tasks/vhosts.yml new file mode 100644 index 0000000..a41401e --- /dev/null +++ b/tasks/vhosts.yml @@ -0,0 +1,22 @@ +--- +- name: Remove default nginx vhost config file (if configured). + file: + path: "{{ nginx_default_vhost_path }}" + state: absent + when: nginx_remove_default_vhost + notify: restart nginx + +- name: Add managed vhost config file (if any vhosts are configured). + template: + src: vhosts.j2 + dest: "{{ nginx_vhost_path }}/vhosts" + mode: 0644 + when: nginx_vhosts + notify: restart nginx + +- name: Remove managed vhost config file (if no vhosts are configured). + file: + path: "{{ nginx_vhost_path }}/vhosts" + state: absent + when: not nginx_vhosts + notify: restart nginx diff --git a/templates/vhosts.j2 b/templates/vhosts.j2 new file mode 100644 index 0000000..4640904 --- /dev/null +++ b/templates/vhosts.j2 @@ -0,0 +1 @@ +# TODO diff --git a/vars/Debian.yml b/vars/Debian.yml index 54bb631..b78b7c5 100644 --- a/vars/Debian.yml +++ b/vars/Debian.yml @@ -1,2 +1,4 @@ --- +nginx_vhost_path: /etc/nginx/sites-enabled +nginx_default_vhost_path: /etc/nginx/sites-enabled/default __nginx_user: "www-data" diff --git a/vars/RedHat.yml b/vars/RedHat.yml index 13d5b86..2412304 100644 --- a/vars/RedHat.yml +++ b/vars/RedHat.yml @@ -1,2 +1,4 @@ --- +nginx_vhost_path: /etc/nginx/conf.d +nginx_default_vhost_path: /etc/nginx/conf.d/default.conf __nginx_user: "nginx"