Each vhost can have his own filename

pull/14/head
Emilien Mantel 2016-03-04 16:38:40 +01:00
parent 26a50945c5
commit 781008dfff
3 changed files with 12 additions and 5 deletions

View File

@ -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

View File

@ -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)

View File

@ -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: