10 Commits

Author SHA1 Message Date
Emilien Mantel
3fdc16578c Improve file deletions 2015-11-30 14:41:35 +01:00
Emilien Mantel
1d56fc249d Deleted vhost don't need a template 2015-11-30 12:16:17 +01:00
Emilien Mantel
bfe4a315f9 Vhost dir 2015-11-05 15:38:18 +01:00
Emilien Mantel
9fcba824f5 Create root directory 2015-11-04 09:16:59 +01:00
Emilien Mantel
d1dbdb83d4 Fix idempotence 2015-11-03 15:09:14 +01:00
Emilien Mantel
bee0cb9a66 Remove template validation 2015-11-03 14:54:35 +01:00
Emilien Mantel
6be44c7da8 Many minor changes 2015-11-03 14:45:01 +01:00
Emilien Mantel
a0a6e35a3a Only reload nginx 2015-11-03 14:38:47 +01:00
Emilien Mantel
f57ab08594 location / can be overwrited 2015-11-03 14:31:50 +01:00
Emilien Mantel
d26a6f26f5 shell module is not necessary 2015-11-02 17:44:09 +01:00
11 changed files with 50 additions and 25 deletions

View File

@@ -44,6 +44,7 @@ Socket:
- `nginx_worker_processes`
- `nginx_events`: key/value in events block
- `nginx_http`: key/value in http block
- `nginx_pid`: daemon pid file
### Vhost management
@@ -54,7 +55,7 @@ You can see many examples in: [tests/test.yml](tests/test.yml).
#### Common
- `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)
- `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
@@ -138,6 +139,4 @@ GPLv2
Author Information
------------------
- You can find many other roles in my GitHub "lab": https://github.com/HanXHX/my-ansible-playbooks
- All issues, pull-request are welcome :)
- Twitter: https://twitter.com/hanxhx

View File

@@ -8,8 +8,9 @@ nginx_apt_package: nginx-full
nginx_root: "/srv/www"
nginx_log_dir: '/var/log/nginx'
nginx_ssl_dir: '/etc/nginx/ssl'
nginx_pid: '/run/nginx.pid'
nginx_resolver:
hosts: ['208.67.222.222', '208.67.220.220'] # OpenDNS
hosts: ['8.8.8.8', '8.8.4.4'] # OpenDNS
valid: '300'
timeout: '5'
nginx_error_log_level: 'warn' # http://nginx.org/en/docs/ngx_core_module.html#error_log

View File

@@ -1,6 +1,4 @@
---
- name: restart nginx
action: service name=nginx state=restarted enabled=yes
- name: reload nginx
action: service name=nginx state=reloaded enabled=yes

View File

@@ -4,7 +4,7 @@ galaxy_info:
description: Nginx for Debian
company:
license: GPLv2
min_ansible_version: 1.2
min_ansible_version: 1.6
platforms:
- name: Debian
versions:

View File

@@ -9,8 +9,10 @@
changed_when: false
- name: TEMPLATE | Deploy nginx.conf
template: src=etc/nginx/nginx.conf.j2 dest=/etc/nginx/nginx.conf validate= "nginx -t"
notify: restart nginx
template: >
src=etc/nginx/nginx.conf.j2
dest=/etc/nginx/nginx.conf
notify: reload nginx
- name: FILE | Create /etc/nginx/helpers
file: dest=/etc/nginx/helpers owner=root mode=0755 state=directory
@@ -24,7 +26,9 @@
# creates: "{{ nginx_dh_path }}"
- name: TEMPLATE | Deploy all helpers
template: src={{ item }} dest=/etc/nginx/helpers/{{ item | basename | regex_replace('\.j2$','') }}
template: >
src={{ item }}
dest=/etc/nginx/helpers/{{ item | basename | regex_replace('\.j2$','') }}
with_fileglob: '../templates/etc/nginx/helpers/*.j2'
notify: reload nginx

View File

@@ -1,6 +1,24 @@
---
- 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)
- 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
@@ -8,7 +26,10 @@
group={{ item.group | default('www-data') }}
mode={{ item.mode | default('0755') }}
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
template: >
@@ -23,8 +44,7 @@
# with_fileglob: "web/*"
- name: FILE | Delete vhosts
file: dest=/etc/nginx/sites-enabled/{{ 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
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
@@ -42,10 +62,10 @@
(item.delete is not defined or not item.delete)
- 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
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)
# file: dest=/etc/nginx/ssl/{{ item.name }} owner=root mode=0750 state=directory

View File

@@ -4,7 +4,7 @@
user {{ nginx_user }};
worker_processes {{ nginx_worker_processes }};
pid /run/nginx.pid;
pid {{ nginx_pid }};
events {
{% for key, value in nginx_events.iteritems() %}

View File

@@ -28,11 +28,13 @@ server {
{% endfor %}
{% endif %}
{% if not __location.has_key('/') %}
location / {
{% block template_try_files %}
try_files {{ override_try_files | default('$uri $uri/ =404') }};
{% endblock %}
}
{% endif %}
{% block template_upstream_location %}
{% endblock %}

View File

@@ -2,5 +2,3 @@ FROM williamyeh/ansible:debian8-onbuild
RUN apt-get update
CMD ["sh", "tests/test.sh"]
EXPOSE 6379

View File

@@ -2,5 +2,3 @@ FROM williamyeh/ansible:debian7-onbuild
RUN apt-get update
CMD ["sh", "tests/test.sh"]
EXPOSE 6379

View File

@@ -30,6 +30,11 @@
- 'return 403;'
'/gunther':
- 'return 404;'
- name: 'test-location.local'
template: '_base'
location:
'/':
- 'alias /var/tmp;'
- name: 'test-php.local'
upstream_params:
- 'fastcgi_param FOO bar;'
@@ -44,7 +49,6 @@
template: '_proxy'
upstream_name: 'test'
- name: 'deleted.local'
template: '_base'
delete: true
roles:
- ../../
@@ -53,9 +57,10 @@
copy: dest="{{ nginx_root }}/{{ item }}/public/index.php" content="<?php phpinfo();"
with_items: ['test-php.local', 'test-php-index.local']
- name: -- Add HTML file --
copy: dest="{{ nginx_root }}/test.local/public/index.html" content="Index HTML test OK\n"
copy: dest="{{ item }}/index.html" content="Index HTML test OK\n"
with_items: ['{{ nginx_root }}/test.local/public', '/var/tmp']
- name: -- VERIFY VHOSTS --
shell: "curl -H 'Host: {{ item.name if item.name is string else item.name[0] }}' http://127.0.0.1{% if item.listen is defined %}:{{ item.listen[0] }}{% endif %}/"
command: "curl -H 'Host: {{ item.name if item.name is string else item.name[0] }}' http://127.0.0.1{% if item.listen is defined %}:{{ item.listen[0] }}{% endif %}/"
with_items: nginx_vhosts
when: item.delete is undefined or not item.delete
changed_when: false
@@ -65,7 +70,7 @@
failed_when: f.stdout.find('403 Forbidden') == -1
changed_when: false
- name: -- VERIFY REDIRECT VHOSTS --
shell: "curl -H 'Host: {{ item.redirect_from[0] }}' http://127.0.0.1/"
command: "curl -H 'Host: {{ item.redirect_from[0] }}' http://127.0.0.1/"
with_items: nginx_vhosts
when: item.redirect_from is defined and (item.delete is undefined or not item.delete)
changed_when: false