mirror of
https://github.com/HanXHX/ansible-nginx.git
synced 2026-02-28 09:22:10 +07:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3fdc16578c | ||
|
|
1d56fc249d | ||
|
|
bfe4a315f9 | ||
|
|
9fcba824f5 |
@@ -55,7 +55,7 @@ You can see many examples in: [tests/test.yml](tests/test.yml).
|
|||||||
#### Common
|
#### Common
|
||||||
|
|
||||||
- `name`: (M) Domain or list of domain used.
|
- `name`: (M) Domain or list of domain used.
|
||||||
- `template`: (M) template used to create vhost
|
- `template`: (M) template used to create vhost. Optional if you set `delete` to true.
|
||||||
- `enable`: (O) Enable the vhost (default is true)
|
- `enable`: (O) Enable the vhost (default is true)
|
||||||
- `delete`: (O) Delete the vhost (default is false)
|
- `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
|
- `redirect_from`: (O) Domain list to redirect to the first `name`. You can use this key to redirect non-www to www
|
||||||
|
|||||||
@@ -1,6 +1,24 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
|
- name: FILE | Create root directory
|
||||||
|
file: >
|
||||||
|
path={{ nginx_root }}
|
||||||
|
state=directory
|
||||||
|
|
||||||
- name: FILE | Create root folders (foreach nginx_vhosts)
|
- 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)
|
||||||
|
|
||||||
|
- name: FILE | Create root public folders (foreach nginx_vhosts)
|
||||||
file: >
|
file: >
|
||||||
path={{ nginx_root }}/{{ item.name if item.name is string else item.name[0] }}/public
|
path={{ nginx_root }}/{{ item.name if item.name is string else item.name[0] }}/public
|
||||||
state=directory
|
state=directory
|
||||||
@@ -8,7 +26,10 @@
|
|||||||
group={{ item.group | default('www-data') }}
|
group={{ item.group | default('www-data') }}
|
||||||
mode={{ item.mode | default('0755') }}
|
mode={{ item.mode | default('0755') }}
|
||||||
with_items: nginx_vhosts
|
with_items: nginx_vhosts
|
||||||
when: item.root is not defined and item.template != '_proxy'
|
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)
|
||||||
|
|
||||||
- name: TEMPLATE | Create vhosts
|
- name: TEMPLATE | Create vhosts
|
||||||
template: >
|
template: >
|
||||||
@@ -23,8 +44,7 @@
|
|||||||
# with_fileglob: "web/*"
|
# with_fileglob: "web/*"
|
||||||
|
|
||||||
- name: FILE | Delete vhosts
|
- name: FILE | Delete vhosts
|
||||||
file: dest=/etc/nginx/sites-enabled/{{ item.name if item.name is string else item.name[0] }} state=absent
|
file: path=/etc/nginx/sites-available/{{ item.name if item.name is string else item.name[0] }} state=absent
|
||||||
file: dest=/etc/nginx/sites-available/{{ item.name if item.name is string else item.name[0] }} state=absent
|
|
||||||
with_items: nginx_vhosts
|
with_items: nginx_vhosts
|
||||||
notify: reload nginx
|
notify: reload nginx
|
||||||
when: item.delete is defined and item.delete
|
when: item.delete is defined and item.delete
|
||||||
@@ -42,10 +62,10 @@
|
|||||||
(item.delete is not defined or not item.delete)
|
(item.delete is not defined or not item.delete)
|
||||||
|
|
||||||
- name: FILE | Disable vhosts
|
- name: FILE | Disable vhosts
|
||||||
file: dest=/etc/nginx/sites-enabled/{{ item.name if item.name is string else item.name[0] }} state=absent
|
file: path=/etc/nginx/sites-enabled/{{ item.name if item.name is string else item.name[0] }} state=absent
|
||||||
with_items: nginx_vhosts
|
with_items: nginx_vhosts
|
||||||
notify: reload nginx
|
notify: reload nginx
|
||||||
when: item.enable is defined and not item.enable
|
when: (item.enable is defined and not item.enable) or (item.delete is defined and item.delete)
|
||||||
|
|
||||||
#- name: FILE | Create ssl dir per vhost (if needed)
|
#- name: FILE | Create ssl dir per vhost (if needed)
|
||||||
# file: dest=/etc/nginx/ssl/{{ item.name }} owner=root mode=0750 state=directory
|
# file: dest=/etc/nginx/ssl/{{ item.name }} owner=root mode=0750 state=directory
|
||||||
|
|||||||
@@ -49,7 +49,6 @@
|
|||||||
template: '_proxy'
|
template: '_proxy'
|
||||||
upstream_name: 'test'
|
upstream_name: 'test'
|
||||||
- name: 'deleted.local'
|
- name: 'deleted.local'
|
||||||
template: '_base'
|
|
||||||
delete: true
|
delete: true
|
||||||
roles:
|
roles:
|
||||||
- ../../
|
- ../../
|
||||||
|
|||||||
Reference in New Issue
Block a user