ansible-nginx/tasks/vhost.yml

94 lines
3.3 KiB
YAML

---
- 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: >
item.proto is defined and
'https' in item.proto and
item.ssl_name is not defined
with_items: nginx_vhosts
- name: FILE | Create root directory
file: >
path={{ nginx_root }}
state=directory
- name: FILE | Create root folders (foreach nginx_vhosts)
file: >
path={{ nginx_root }}/{{ item.name if item.name is string else item.name[0] }}
state=directory
owner={{ item.owner | default('www-data') }}
group={{ item.group | default('www-data') }}
mode={{ item.mode | default('0755') }}
with_items: nginx_vhosts
when: >
item.root is not defined and
(item.template is defined and item.template != '_proxy') and
(item.delete is not defined or not item.delete) and
item.redirect_to is not defined
- name: FILE | Create root public folders (foreach nginx_vhosts)
file: >
path={{ nginx_root }}/{{ item.name if item.name is string else item.name[0] }}/public
state=directory
owner={{ item.owner | default('www-data') }}
group={{ item.group | default('www-data') }}
mode={{ item.mode | default('0755') }}
with_items: nginx_vhosts
when: >
item.root is not defined and
(item.template is defined and item.template != '_proxy') and
(item.delete is not defined or not item.delete) and
item.redirect_to is not defined
- 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] }}
with_items: nginx_vhosts
notify: reload nginx
when: item.delete is not defined or not item.delete
#- name: COPY | Add index.html / index.php
# copy: src={{ item }} dest={{ nginx_root }}/{{ item.name }}/public/{{ item }} owner=www-data group=www-data mode=0666
# with_fileglob: "web/*"
- name: FILE | Delete vhosts
file: path=/etc/nginx/sites-available/{{ 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] }}
state=link
with_items: nginx_vhosts
notify: reload nginx
when: >
((item.enable is not defined) or
(item.enable is defined and item.enable)) and
(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
with_items: nginx_vhosts
notify: reload nginx
when: (item.enable is defined and not item.enable) or (item.delete is defined and item.delete)
- name: FILE | Delete default vhost when explicitely defined
file: >
path=/etc/nginx/sites-enabled/default
state=absent
notify: reload nginx
when: nginx_default_vhost is not none
- name: FILE | Auto set default vhost
file: >
src=/etc/nginx/sites-available/default
dest=/etc/nginx/sites-enabled/default
state=link
notify: reload nginx
when: nginx_default_vhost is none