2015-07-15 20:18:51 +07:00
|
|
|
---
|
|
|
|
|
2016-03-09 17:15:37 +07:00
|
|
|
- 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'
|
2016-03-15 01:21:47 +07:00
|
|
|
with_items: "{{ nginx_vhosts }}"
|
2016-03-09 17:15:37 +07:00
|
|
|
|
2016-01-12 20:40:09 +07:00
|
|
|
- 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] }}"
|
2016-01-12 21:01:01 +07:00
|
|
|
when: >
|
|
|
|
item.proto is defined and
|
|
|
|
'https' in item.proto and
|
|
|
|
item.ssl_name is not defined
|
2016-03-05 17:37:37 +07:00
|
|
|
with_items: "{{ nginx_vhosts }}"
|
2016-01-12 20:40:09 +07:00
|
|
|
|
2016-03-15 15:22:01 +07:00
|
|
|
- name: FAIL | Check HTTPS redir and proto
|
|
|
|
fail: msg="You can't have HTTP proto and HTTPS redirection at the same time"
|
|
|
|
when: >
|
|
|
|
((item.proto is defined and 'http' in item.proto) or (item.proto is not defined)) and
|
|
|
|
(item.redirect_http is defined and item.redirect_http)
|
|
|
|
with_items: "{{ nginx_vhosts }}"
|
|
|
|
|
2015-11-04 15:16:59 +07:00
|
|
|
- name: FILE | Create root directory
|
|
|
|
file: >
|
|
|
|
path={{ nginx_root }}
|
|
|
|
state=directory
|
|
|
|
|
2015-11-05 21:38:18 +07:00
|
|
|
- name: FILE | Create root public folders (foreach nginx_vhosts)
|
2015-07-30 18:02:21 +07:00
|
|
|
file: >
|
2016-10-07 15:50:05 +07:00
|
|
|
path={{ nginx_root }}/{{ item.filename | default(item.name if item.name is string else item.name[0]) }}/public
|
2015-07-30 18:02:21 +07:00
|
|
|
state=directory
|
2016-03-05 21:07:39 +07:00
|
|
|
owner={{ item.owner | default(nginx_user) }}
|
|
|
|
group={{ item.group | default(nginx_user) }}
|
2015-07-30 18:02:21 +07:00
|
|
|
mode={{ item.mode | default('0755') }}
|
2016-03-05 17:37:37 +07:00
|
|
|
with_items: "{{ nginx_vhosts }}"
|
2015-11-30 18:16:17 +07:00
|
|
|
when: >
|
|
|
|
item.root is not defined and
|
2016-01-22 15:46:43 +07:00
|
|
|
(item.template is defined and item.template not in nginx_templates_no_dir) and
|
2016-08-30 16:06:38 +07:00
|
|
|
(item.state is not defined or not item.state != 'absent') and
|
2015-12-01 21:46:57 +07:00
|
|
|
item.redirect_to is not defined
|
2015-07-15 20:18:51 +07:00
|
|
|
|
|
|
|
- name: TEMPLATE | Create vhosts
|
2015-07-30 18:02:21 +07:00
|
|
|
template: >
|
2015-12-01 21:46:57 +07:00
|
|
|
src=etc/nginx/sites-available/{{ item.template if item.redirect_to is not defined else '_redirect' }}.j2
|
2016-03-09 17:15:37 +07:00
|
|
|
dest={{ nginx_etc_dir }}/sites-available/{{ item.filename | default(item.name if item.name is string else item.name[0]) }}
|
2016-03-05 17:37:37 +07:00
|
|
|
with_items: "{{ nginx_vhosts }}"
|
2016-03-16 05:00:55 +07:00
|
|
|
notify: ['reload nginx', 'restart nginx freebsd']
|
2016-08-30 16:18:14 +07:00
|
|
|
when: item.state is not defined or item.state != 'absent'
|
2015-07-15 20:18:51 +07:00
|
|
|
|
2015-07-30 18:02:21 +07:00
|
|
|
- name: FILE | Delete vhosts
|
2016-03-09 17:15:37 +07:00
|
|
|
file: path={{ nginx_etc_dir }}/sites-available/{{ item.filename | default(item.name if item.name is string else item.name[0]) }} state=absent
|
2016-03-05 17:37:37 +07:00
|
|
|
with_items: "{{ nginx_vhosts }}"
|
2016-03-16 05:00:55 +07:00
|
|
|
notify: ['reload nginx', 'restart nginx freebsd']
|
2016-08-30 16:06:38 +07:00
|
|
|
when: item.state is defined and item.state == 'absent'
|
2015-07-30 18:02:21 +07:00
|
|
|
|
|
|
|
- name: FILE | Enable vhosts
|
|
|
|
file: >
|
2016-03-09 17:15:37 +07:00
|
|
|
src={{ nginx_etc_dir }}/sites-available/{{ item.filename | default(item.name if item.name is string else item.name[0]) }}
|
|
|
|
dest={{ nginx_etc_dir }}/sites-enabled/{{ item.filename | default(item.name if item.name is string else item.name[0]) }}
|
2015-07-30 18:02:21 +07:00
|
|
|
state=link
|
2016-03-05 17:37:37 +07:00
|
|
|
with_items: "{{ nginx_vhosts }}"
|
2016-03-16 05:00:55 +07:00
|
|
|
notify: ['reload nginx', 'restart nginx freebsd']
|
2015-07-31 06:02:37 +07:00
|
|
|
when: >
|
2016-08-30 16:06:38 +07:00
|
|
|
item.state is not defined or item.state == 'present'
|
2015-07-15 20:18:51 +07:00
|
|
|
|
2015-07-30 18:02:21 +07:00
|
|
|
- name: FILE | Disable vhosts
|
2016-03-09 17:15:37 +07:00
|
|
|
file: path={{ nginx_etc_dir}}/sites-enabled/{{ item.filename | default(item.name if item.name is string else item.name[0]) }} state=absent
|
2016-03-05 17:37:37 +07:00
|
|
|
with_items: "{{ nginx_vhosts }}"
|
2016-03-16 05:00:55 +07:00
|
|
|
notify: ['reload nginx', 'restart nginx freebsd']
|
2016-08-30 16:06:38 +07:00
|
|
|
when: item.state is defined and item.state == 'disabled'
|
2015-07-30 18:02:21 +07:00
|
|
|
|
2016-01-21 23:08:01 +07:00
|
|
|
- name: FILE | Delete default vhost when explicitely defined
|
|
|
|
file: >
|
2016-03-05 21:07:39 +07:00
|
|
|
path={{ nginx_etc_dir }}/sites-enabled/default
|
2016-01-21 23:08:01 +07:00
|
|
|
state=absent
|
2016-03-16 05:00:55 +07:00
|
|
|
notify: ['reload nginx', 'restart nginx freebsd']
|
2016-01-21 23:08:01 +07:00
|
|
|
when: nginx_default_vhost is not none
|
|
|
|
|
|
|
|
- name: FILE | Auto set default vhost
|
|
|
|
file: >
|
2016-03-05 21:07:39 +07:00
|
|
|
src={{ nginx_etc_dir }}/sites-available/default
|
|
|
|
dest={{ nginx_etc_dir }}/sites-enabled/default
|
2016-01-21 23:08:01 +07:00
|
|
|
state=link
|
2016-03-16 05:00:55 +07:00
|
|
|
notify: ['reload nginx', 'restart nginx freebsd']
|
2016-01-21 23:08:01 +07:00
|
|
|
when: nginx_default_vhost is none
|