ansible-nginx/tasks/vhost.yml

66 lines
2.3 KiB
YAML
Raw Normal View History

2015-07-15 20:18:51 +07:00
---
- name: FILE | Create root folders (foreach nginx_vhosts)
2015-07-30 18:02:21 +07:00
file: >
path={{ nginx_root }}/{{ item.name[0] }}/public
state=directory
owner={{ item.owner | default('www-data') }}
group={{ item.group | default('www-data') }}
mode={{ item.mode | default('0755') }}
2015-07-15 20:18:51 +07:00
with_items: nginx_vhosts
2015-10-08 23:21:40 +07:00
when: item.root is not defined and item.template != '_proxy'
2015-07-15 20:18:51 +07:00
- name: TEMPLATE | Create vhosts
2015-07-30 18:02:21 +07:00
template: >
src=etc/nginx/sites-available/{{ item.template }}.j2
dest=/etc/nginx/sites-available/{{ item.name[0] }}
2015-07-15 20:18:51 +07:00
with_items: nginx_vhosts
notify: reload nginx
2015-07-31 06:02:37 +07:00
when: item.delete is not defined or not item.delete
2015-07-15 20:18:51 +07:00
#- 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
2015-07-15 20:42:32 +07:00
# with_fileglob: "web/*"
2015-07-15 20:18:51 +07:00
2015-07-30 18:02:21 +07:00
- name: FILE | Delete vhosts
file: dest=/etc/nginx/sites-enabled/{{ item.name[0] }} state=absent
file: dest=/etc/nginx/sites-available/{{ 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[0] }}
dest=/etc/nginx/sites-enabled/{{ item.name[0] }}
state=link
2015-07-15 20:18:51 +07:00
with_items: nginx_vhosts
notify: reload nginx
2015-07-31 06:02:37 +07:00
when: >
((item.enable is not defined) or
(item.enable is defined and item.enable)) and
(item.delete is not defined or not item.delete)
2015-07-15 20:18:51 +07:00
2015-07-30 18:02:21 +07:00
- name: FILE | Disable vhosts
file: dest=/etc/nginx/sites-enabled/{{ item.name[0] }} state=absent
2015-07-15 20:18:51 +07:00
with_items: nginx_vhosts
2015-07-30 18:02:21 +07:00
notify: reload nginx
2015-07-31 06:02:37 +07:00
when: item.enable is defined and not item.enable
2015-07-30 18:02:21 +07:00
#- name: FILE | Create ssl dir per vhost (if needed)
# file: dest=/etc/nginx/ssl/{{ item.name }} owner=root mode=0750 state=directory
# with_items: nginx_vhosts
# when: item.ssl.use is defined and item.ssl.use
2015-07-15 20:18:51 +07:00
# TODO...
#- name: COPY | Deploy SSL keys if needed
# copy: src=keys/{{ item.name }}/{{ item.name }}.crt dest=/etc/nginx/ssl/{{ item.name }} mode=660
# copy: src=keys/{{ item.name }}/{{ item.name }}.key dest=/etc/nginx/ssl/{{ item.name }} mode=660
# with_items: nginx_vhosts
# when: item.ssl.use and not generatekey
# TODO:
# - deploy defaults files (index.html/index.php) allready in files/
# - work with role "ssl_autosign"