diff --git a/tasks/main.yml b/tasks/main.yml index 01b42a0..2b7f306 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -20,5 +20,6 @@ - name: "[NGINX] - Create Vhosts configuration" include_tasks: vhost.yml + loop: '{{ nginx_vhosts }}' diff --git a/tasks/vhost.yml b/tasks/vhost.yml index 3b27c44..864aeb0 100644 --- a/tasks/vhost.yml +++ b/tasks/vhost.yml @@ -1,6 +1,11 @@ --- +- name: '[ONION] - register onion address' + slurp: + src: "/var/lib/tor/{{ item.name }}/hostname" + register: "onion_address" + when: item.onion is defined and item.onion == 'true' -- name: "[NGINX] - Create vhosts" +- name: "[NGINX] - Set fact" set_fact: enable_tor: 'false' @@ -8,7 +13,6 @@ template: src: etc/nginx/sites-available/{{ item.template }}.j2 dest: "{{ nginx_etc_dir }}/sites-available/{{ item.name }}" - with_items: "{{ nginx_vhosts }}" notify: - reload nginx when: item.state is defined and item.state != 'delete' @@ -17,7 +21,6 @@ file: path: "{{ nginx_etc_dir }}/sites-available/{{ item.name }}" state: absent - with_items: "{{ nginx_vhosts }}" notify: - reload nginx when: item.state is defined and item.state == 'delete' @@ -27,7 +30,6 @@ src: "{{ nginx_etc_dir }}/sites-available/{{ item.name }}" dest: "{{ nginx_etc_dir }}/sites-enabled/{{ item.name }}" state: link - with_items: "{{ nginx_vhosts }}" notify: - reload nginx when: item.state is defined and item.state == 'enable' @@ -36,7 +38,6 @@ file: path: "{{ nginx_etc_dir}}/sites-enabled/{{ item.name }}" state: absent - with_items: "{{ nginx_vhosts }}" notify: - reload nginx when: item.state is defined and (item.state == 'disable' or item.state == 'delete') @@ -53,7 +54,6 @@ template: src: etc/nginx/sites-available/maintenance.j2 dest: "{{ nginx_etc_dir }}/sites-available/maintenance-{{ item.name }}" - with_items: "{{ nginx_vhosts }}" notify: - reload nginx when: (item.state is defined) and (item.state != 'delete') and (item.maintenance is defined) and (item.maintenance == 'true') diff --git a/templates/etc/nginx/sites-available/core.j2 b/templates/etc/nginx/sites-available/core.j2 index 0e62070..5ec50b7 100644 --- a/templates/etc/nginx/sites-available/core.j2 +++ b/templates/etc/nginx/sites-available/core.j2 @@ -52,6 +52,9 @@ server { {% endblock %} {% block headers %} +{% if enable_tor != 'true' and item.onion is defined and onion_address | length > 0 %} + add_header Onion-Location http://{{ onion_address.content | b64decode | trim }}$request_uri; +{% endif %} {% if item.headers is defined and item.headers == 'none' %} {% else %} ## HEADERS diff --git a/templates/etc/tor/torrc.j2 b/templates/etc/tor/torrc.j2 index 4f3afb4..42937d2 100644 --- a/templates/etc/tor/torrc.j2 +++ b/templates/etc/tor/torrc.j2 @@ -71,7 +71,7 @@ {% for item in nginx_vhosts %} {% if item.onion is defined and item.onion == 'true' %} HiddenServiceDir /var/lib/tor/{{ item.name }}/ -HiddenServicePort {{ item.listen }} unix:/var/run/{{ item.name }}.sock +HiddenServicePort {{ item.torlisten }} unix:/var/run/{{ item.name }}.sock {% endif %} {% endfor %}