From 781008dfffc0f8ed56b6f410db15f3eea6ddbda8 Mon Sep 17 00:00:00 2001 From: Emilien Mantel Date: Fri, 4 Mar 2016 16:38:40 +0100 Subject: [PATCH] Each vhost can have his own filename --- doc/vhost.md | 1 + tasks/vhost.yml | 15 ++++++++++----- tests/test.yml | 1 + 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/doc/vhost.md b/doc/vhost.md index 086eb5e..c0091f8 100644 --- a/doc/vhost.md +++ b/doc/vhost.md @@ -10,6 +10,7 @@ Common - `name`: (M) Domain or list of domain used. - `template`: (D) template used to create vhost. Optional if you set `delete` to true or using `redirect_tor`. +- `filename`: (O) Specify filename in /etc/nginx/sites-*. Do NOT specify default (reserved keyword). - `enable`: (O) Enable the vhost (default is true) - `delete`: (O) Delete the vhost (default is false) - `redirect_from`: (O) Domain list to redirect to the first `name`. You can use this key to redirect non-www to www diff --git a/tasks/vhost.yml b/tasks/vhost.yml index 9ec8d00..ecdbe05 100644 --- a/tasks/vhost.yml +++ b/tasks/vhost.yml @@ -1,5 +1,10 @@ --- +- name: FAIL | Check filenames + fail: msg="Forbidden keyword default on vhost {{ item.name if item.name is string else item.name[0] }}" + when: item.filename is defined and item.filename == 'default' + with_items: nginx_vhosts + - name: FAIL | Check vhost and SSL/TLS support fail: msg="Missmatch configuration for vhost {{ item.name if item.name is string else item.name[0] }}" when: > @@ -30,21 +35,21 @@ - name: TEMPLATE | Create vhosts template: > src=etc/nginx/sites-available/{{ item.template if item.redirect_to is not defined else '_redirect' }}.j2 - dest=/etc/nginx/sites-available/{{ item.name if item.name is string else item.name[0] }} + dest=/etc/nginx/sites-available/{{ item.filename | default(item.name if item.name is string else item.name[0]) }} with_items: nginx_vhosts notify: reload nginx when: item.delete is not defined or not item.delete - name: FILE | Delete vhosts - file: path=/etc/nginx/sites-available/{{ item.name if item.name is string else item.name[0] }} state=absent + file: path=/etc/nginx/sites-available/{{ item.filename | default(item.name if item.name is string else item.name[0]) }} state=absent with_items: nginx_vhosts notify: reload nginx when: item.delete is defined and item.delete - name: FILE | Enable vhosts file: > - src=/etc/nginx/sites-available/{{ item.name if item.name is string else item.name[0] }} - dest=/etc/nginx/sites-enabled/{{ item.name if item.name is string else item.name[0] }} + src=/etc/nginx/sites-available/{{ item.filename | default(item.name if item.name is string else item.name[0]) }} + dest=/etc/nginx/sites-enabled/{{ item.filename | default(item.name if item.name is string else item.name[0]) }} state=link with_items: nginx_vhosts notify: reload nginx @@ -54,7 +59,7 @@ (item.delete is not defined or not item.delete) - name: FILE | Disable vhosts - file: path=/etc/nginx/sites-enabled/{{ item.name if item.name is string else item.name[0] }} state=absent + file: path=/etc/nginx/sites-enabled/{{ item.filename | default(item.name if item.name is string else item.name[0]) }} state=absent with_items: nginx_vhosts notify: reload nginx when: (item.enable is defined and not item.enable) or (item.delete is defined and item.delete) diff --git a/tests/test.yml b/tests/test.yml index addf686..e59b2ba 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -119,6 +119,7 @@ - 'test-alias.local' - 'test2-alias.local' template: '_base' + filename : 'first-test' override_try_files: '$uri $uri index.htm index.html' manage_local_content: false more: