fix #101: enable symlinked vhosts

On Debian based systems the vhosts are symlinked when enabled.
This patch makes the role compatible with that workflow.
pull/126/head
Ilan Cohen 7 years ago
parent 7aa2ea4779
commit a013d07efb
  1. 17
      tasks/vhosts.yml
  2. 4
      templates/nginx.conf.j2
  3. 3
      vars/Debian.yml

@ -32,6 +32,23 @@
with_items: "{{ nginx_vhosts }}"
notify: reload nginx
- name: Enable managed vhost config files.
file:
src: "{{ nginx_vhost_path }}/{{ item.filename|default(item.server_name.split(' ')[0] ~ '.conf') }}"
dest: "{{ nginx_vhost_symlink_path }}/{{ item.filename|default(item.server_name.split(' ')[0] ~ '.conf') }}"
state: link
when: nginx_vhost_symlink_path is defined and item.enabled|default(true) != false
with_items: "{{ nginx_vhosts }}"
notify: reload nginx
- name: Disable managed vhost config files.
file:
path: "{{ nginx_vhost_symlink_path }}/{{ item.filename|default(item.server_name.split(' ')[0] ~ '.conf') }}"
state: absent
when: nginx_vhost_symlink_path is defined and item.enabled|default(true) == false
with_items: "{{ nginx_vhosts }}"
notify: reload nginx
- name: Remove legacy vhosts.conf file.
file:
path: "{{ nginx_vhost_path }}/vhosts.conf"

@ -72,7 +72,9 @@ http {
{% block http_includes %}
include {{ nginx_conf_path }}/*.conf;
{% if nginx_conf_path != nginx_vhost_path %}
{% if nginx_vhost_symlink_path is defined %}
include {{ nginx_vhost_symlink_path }}/*;
{% elif nginx_conf_path != nginx_vhost_path %}
include {{ nginx_vhost_path }}/*;
{% endif %}
{% endblock %}

@ -4,6 +4,7 @@ nginx_conf_path: /etc/nginx/conf.d
nginx_conf_file_path: /etc/nginx/nginx.conf
nginx_mime_file_path: /etc/nginx/mime.types
nginx_pidfile: /run/nginx.pid
nginx_vhost_path: /etc/nginx/sites-enabled
nginx_vhost_path: /etc/nginx/sites-available
nginx_vhost_symlink_path: /etc/nginx/sites-enabled
nginx_default_vhost_path: /etc/nginx/sites-enabled/default
__nginx_user: "www-data"