mirror of
https://github.com/HanXHX/ansible-nginx.git
synced 2026-02-28 09:22:10 +07:00
Compare commits
51 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
38a8354754 | ||
|
|
1b06fe273f | ||
|
|
684c794566 | ||
|
|
f2cfae31b1 | ||
|
|
481bcd34b1 | ||
|
|
875c7cfb2e | ||
|
|
8caddedc68 | ||
|
|
4a3aed6974 | ||
|
|
8ccc9f521f | ||
|
|
5b0977567c | ||
|
|
de71e1bdcc | ||
|
|
19cdab5ba4 | ||
|
|
999f226838 | ||
|
|
40f67fc103 | ||
|
|
6b1366298f | ||
|
|
817d56fb81 | ||
|
|
e08401acf8 | ||
|
|
0bda544a2f | ||
|
|
2641777abe | ||
|
|
60a368f3e1 | ||
|
|
41a5575627 | ||
|
|
42bb4a3e2b | ||
|
|
ef3440a015 | ||
|
|
eb704da8d8 | ||
|
|
64a9ab7c68 | ||
|
|
c4ee6eb1a2 | ||
|
|
8789bd2c9c | ||
|
|
a2e6e98436 | ||
|
|
fc44b704cf | ||
|
|
cf662acdd7 | ||
|
|
34c8d1926f | ||
|
|
634d88874f | ||
|
|
5e254331c4 | ||
|
|
3ab8e0391c | ||
|
|
aac33b7376 | ||
|
|
88c6c5a043 | ||
|
|
a9ad41b40f | ||
|
|
d26b2b9a49 | ||
|
|
b17acac4c4 | ||
|
|
c160640c7f | ||
|
|
887219f86c | ||
|
|
76c02abf47 | ||
|
|
26c93c9315 | ||
|
|
8fb3829860 | ||
|
|
e4b5bb2a32 | ||
|
|
af3930a58a | ||
|
|
4dcb5f44c6 | ||
|
|
1204dbacd1 | ||
|
|
3087154335 | ||
|
|
72edbe8656 | ||
|
|
66b2ac238c |
12
.travis.yml
12
.travis.yml
@@ -1,16 +1,20 @@
|
|||||||
env:
|
matrix:
|
||||||
- PLATFORM=debian-wheezy
|
include:
|
||||||
- PLATFORM=debian-jessie
|
- env: PLATFORM=debian-jessie ORIGIN=debian NGINX_PHP56=true NGINX_PHP70=false NGINX_BACKPORTS=false DOTDEB=false
|
||||||
|
- env: PLATFORM=debian-jessie ORIGIN=backports NGINX_PHP56=true NGINX_PHP70=false NGINX_BACKPORTS=true DOTDEB=false
|
||||||
|
- env: PLATFORM=debian-jessie ORIGIN=dotdeb NGINX_PHP56=true NGINX_PHP70=true NGINX_BACKPORTS=false DOTDEB=true
|
||||||
|
|
||||||
sudo: required
|
sudo: required
|
||||||
|
|
||||||
|
dist: trusty
|
||||||
|
|
||||||
language: python
|
language: python
|
||||||
|
|
||||||
services:
|
services:
|
||||||
- docker
|
- docker
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- docker build -f tests/$PLATFORM.Dockerfile -t test-$PLATFORM . && docker run --name $PLATFORM test-$PLATFORM
|
- docker build -f tests/$PLATFORM.Dockerfile -t test-$PLATFORM . && docker run -e "DOTDEB=$DOTDEB" -e "NGINX_PHP56=$NGINX_PHP56" -e "NGINX_PHP70=$NGINX_PHP70" -e "NGINX_BACKPORTS=$NGINX_BACKPORTS" --name $PLATFORM test-$PLATFORM
|
||||||
|
|
||||||
notifications:
|
notifications:
|
||||||
webhooks: https://galaxy.ansible.com/api/v1/notifications/
|
webhooks: https://galaxy.ansible.com/api/v1/notifications/
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
Nginx for Debian/FreeBSD Ansible role
|
Nginx for Debian/FreeBSD Ansible role
|
||||||
=====================================
|
=====================================
|
||||||
|
|
||||||
[](https://galaxy.ansible.com/list#/roles/4399) [](https://travis-ci.org/HanXHX/ansible-nginx)
|
[](https://galaxy.ansible.com/HanXHX/nginx/) [](https://travis-ci.org/HanXHX/ansible-nginx)
|
||||||
|
|
||||||
Install and configure Nginx on Debian/FreeBSD.
|
Install and configure Nginx on Debian/FreeBSD.
|
||||||
|
|
||||||
@@ -13,6 +13,9 @@ Features:
|
|||||||
- Fast PHP configuration
|
- Fast PHP configuration
|
||||||
- Preconfigured vhost templates (should work on many app)
|
- Preconfigured vhost templates (should work on many app)
|
||||||
- Auto-configure HTTP2 on SSL/TLS vhosts
|
- Auto-configure HTTP2 on SSL/TLS vhosts
|
||||||
|
- Manage dynamic modules (install and loading)
|
||||||
|
- Deploy custom facts.d with sites config
|
||||||
|
- Can listen with proxy protocol
|
||||||
|
|
||||||
Requirements
|
Requirements
|
||||||
------------
|
------------
|
||||||
@@ -40,6 +43,7 @@ FreeBSD:
|
|||||||
- `nginx_resolver`: list of DNS resolver (default: OpenDNS)
|
- `nginx_resolver`: list of DNS resolver (default: OpenDNS)
|
||||||
- `nginx_error_log_level`: default log level
|
- `nginx_error_log_level`: default log level
|
||||||
- `nginx_auto_config_httpv2`: boolean, auto configure HTTP2 where possible
|
- `nginx_auto_config_httpv2`: boolean, auto configure HTTP2 where possible
|
||||||
|
- `nginx_fastcgi_fix_realpath`: boolean, use realpath for fastcgi (fix problems with symlinks and PHP opcache)
|
||||||
|
|
||||||
### Nginx Configuration
|
### Nginx Configuration
|
||||||
|
|
||||||
@@ -49,6 +53,7 @@ FreeBSD:
|
|||||||
- `nginx_events_*`: all variables in events block
|
- `nginx_events_*`: all variables in events block
|
||||||
- `nginx_http_*`: all variables in http block
|
- `nginx_http_*`: all variables in http block
|
||||||
- `nginx_custom_http`: instructions list (will put data in `/etc/nginx/conf.d/custom.conf`)
|
- `nginx_custom_http`: instructions list (will put data in `/etc/nginx/conf.d/custom.conf`)
|
||||||
|
- `nginx_dyn_modules`: dynamic module list to load
|
||||||
|
|
||||||
Fine configuration
|
Fine configuration
|
||||||
------------------
|
------------------
|
||||||
|
|||||||
24
Vagrantfile
vendored
24
Vagrantfile
vendored
@@ -6,13 +6,14 @@
|
|||||||
Vagrant.configure("2") do |config|
|
Vagrant.configure("2") do |config|
|
||||||
|
|
||||||
vms_debian = [
|
vms_debian = [
|
||||||
[ "debian-wheezy", "debian/wheezy64" ],
|
{ :name => "debian-jessie", :box => "debian/jessie64", :vars => { "nginx_php56": true, "nginx_php70": false, "dotdeb": false, "nginx_backports": false }},
|
||||||
[ "debian-jessie", "debian/jessie64" ],
|
{ :name => "debian-jessie-backports", :box => "debian/jessie64", :vars => { "nginx_php56": true, "nginx_php70": false, "dotdeb": false, "nginx_backports": true }},
|
||||||
[ "debian-stretch", "sharlak/debian_stretch_64" ],
|
{ :name => "debian-jessie-dotdeb", :box => "debian/jessie64", :vars => { "nginx_php56": true, "nginx_php70": true, "dotdeb": true, "nginx_backports": false }},
|
||||||
|
{ :name => "debian-stretch", :box => "sharlak/debian_stretch_64", :vars => { "nginx_php56": false, "nginx_php70": true, "dotdeb": false, "nginx_backports": false }}
|
||||||
]
|
]
|
||||||
|
|
||||||
vms_freebsd = [
|
vms_freebsd = [
|
||||||
[ "freebsd-10.2", "freebsd/FreeBSD-10.2-STABLE" ]
|
{ :name => "freebsd-10.2", :box => "freebsd/FreeBSD-10.2-STABLE" }
|
||||||
]
|
]
|
||||||
|
|
||||||
config.vm.provider "virtualbox" do |v|
|
config.vm.provider "virtualbox" do |v|
|
||||||
@@ -20,22 +21,22 @@ Vagrant.configure("2") do |config|
|
|||||||
v.memory = 256
|
v.memory = 256
|
||||||
end
|
end
|
||||||
|
|
||||||
vms_debian.each do |vm|
|
vms_debian.each do |opts|
|
||||||
config.vm.define vm[0] do |m|
|
config.vm.define opts[:name] do |m|
|
||||||
m.vm.box = vm[1]
|
m.vm.box = opts[:box]
|
||||||
m.vm.network "private_network", type: "dhcp"
|
m.vm.network "private_network", type: "dhcp"
|
||||||
m.vm.provision "ansible" do |ansible|
|
m.vm.provision "ansible" do |ansible|
|
||||||
ansible.playbook = "tests/test.yml"
|
ansible.playbook = "tests/test.yml"
|
||||||
ansible.groups = { "test" => [ vm[0] ] }
|
|
||||||
ansible.verbose = 'vv'
|
ansible.verbose = 'vv'
|
||||||
ansible.sudo = true
|
ansible.sudo = true
|
||||||
|
ansible.extra_vars = opts[:vars]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
# See: https://forums.freebsd.org/threads/52717/
|
# See: https://forums.freebsd.org/threads/52717/
|
||||||
vms_freebsd.each do |vm|
|
vms_freebsd.each do |opts|
|
||||||
config.vm.define vm[0] do |m|
|
config.vm.define opts[:name] do |m|
|
||||||
m.vm.box = vm[1]
|
m.vm.box = opts[:box]
|
||||||
m.vm.network "private_network", type: "dhcp"
|
m.vm.network "private_network", type: "dhcp"
|
||||||
m.vm.guest = :freebsd
|
m.vm.guest = :freebsd
|
||||||
m.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: true
|
m.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: true
|
||||||
@@ -44,7 +45,6 @@ Vagrant.configure("2") do |config|
|
|||||||
m.vm.provision "shell", inline: "pkg install -y python bash"
|
m.vm.provision "shell", inline: "pkg install -y python bash"
|
||||||
m.vm.provision "ansible" do |ansible|
|
m.vm.provision "ansible" do |ansible|
|
||||||
ansible.playbook = "tests/test.yml"
|
ansible.playbook = "tests/test.yml"
|
||||||
ansible.groups = { "test" => [ vm[0] ] }
|
|
||||||
ansible.verbose = 'vv'
|
ansible.verbose = 'vv'
|
||||||
ansible.sudo = true
|
ansible.sudo = true
|
||||||
ansible.extra_vars = {
|
ansible.extra_vars = {
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ nginx_error_log_level: 'warn' # http://nginx.org/en/docs/ngx_core_module.html#er
|
|||||||
nginx_auto_config_httpv2: true
|
nginx_auto_config_httpv2: true
|
||||||
nginx_default_vhost: null
|
nginx_default_vhost: null
|
||||||
nginx_default_vhost_ssl: null
|
nginx_default_vhost_ssl: null
|
||||||
|
nginx_fastcgi_fix_realpath: true
|
||||||
|
|
||||||
#
|
#
|
||||||
# Nginx directories
|
# Nginx directories
|
||||||
@@ -31,9 +32,12 @@ nginx_helper_dir: '{{ nginx_etc_dir}}/helper'
|
|||||||
#
|
#
|
||||||
|
|
||||||
# PHP
|
# PHP
|
||||||
nginx_php: false
|
nginx_php56: false
|
||||||
nginx_php_sockets:
|
nginx_php70: false
|
||||||
- unix_socket: "/var/run/php5-fpm.sock"
|
nginx_php56_sockets:
|
||||||
|
- unix_socket: "/run/php5-fpm.sock"
|
||||||
|
nginx_php70_sockets:
|
||||||
|
- unix_socket: "/run/php/php7.0-fpm.sock"
|
||||||
nginx_upstreams: []
|
nginx_upstreams: []
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -101,9 +105,21 @@ nginx_htpasswd: []
|
|||||||
#
|
#
|
||||||
nginx_ssl_pairs: []
|
nginx_ssl_pairs: []
|
||||||
|
|
||||||
|
#
|
||||||
|
# Dynamic modules
|
||||||
|
#
|
||||||
|
nginx_dyn_modules: []
|
||||||
|
|
||||||
#
|
#
|
||||||
# Diffie-Hellman
|
# Diffie-Hellman
|
||||||
#
|
#
|
||||||
nginx_dh: null
|
nginx_dh: null
|
||||||
nginx_dh_path: '{{ nginx_ssl_dir }}/dhparam.pem'
|
nginx_dh_path: '{{ nginx_ssl_dir }}/dhparam.pem'
|
||||||
nginx_dh_length: 2048
|
nginx_dh_length: 2048
|
||||||
|
|
||||||
|
# Extra
|
||||||
|
|
||||||
|
# Note:
|
||||||
|
# - On Debian, if you use Owncloud from Upstream repository, you must set this var to "/var/www/owncloud"
|
||||||
|
# - TODO: force this var in vars/FreeBSD.yml
|
||||||
|
nginx_owncloud_root: '/usr/share/owncloud'
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
PHP
|
PHP
|
||||||
===
|
===
|
||||||
|
|
||||||
- `nginx_php`: boolean if you need to preconfigure PHP (default: false)
|
- `nginx_php56` and `nginx_php70`: boolean if you need to preconfigure PHP (default: false)
|
||||||
- `nginx_php_sockets`: list of sockets (see bellow)
|
- `nginx_php##_sockets`: list of sockets (see bellow)
|
||||||
|
|
||||||
You should see [Nginx upstream module doc](http://nginx.org/en/docs/http/ngx_http_upstream_module.html).
|
You should see [Nginx upstream module doc](http://nginx.org/en/docs/http/ngx_http_upstream_module.html).
|
||||||
|
|
||||||
@@ -15,4 +15,4 @@ Each socket have:
|
|||||||
- `max_fails`
|
- `max_fails`
|
||||||
- `fail_timeout`
|
- `fail_timeout`
|
||||||
|
|
||||||
With default configuration, it works fine with PHP-FPM. But if you install PHP7 with Dotdeb, path changed between version, you must set well this list.
|
With default configuration, it works fine with PHP-FPM.
|
||||||
|
|||||||
16
doc/ssl.md
16
doc/ssl.md
@@ -32,7 +32,8 @@ Note: `name` is used to deploy key/cert. With defaults values dans `name` = "foo
|
|||||||
Tips
|
Tips
|
||||||
----
|
----
|
||||||
|
|
||||||
Deploying key/cert is not mandatory with this role. You can manage it in other place ([letsencrypt](https://letsencrypt.org/)? :)). You just need to set `dest_cert` and `dest_key`!
|
- Deploying key/cert is not mandatory with this role. You can manage it in other place ([letsencrypt](https://letsencrypt.org/)? :)). You just need to set `dest_cert` and `dest_key`!
|
||||||
|
- In `nginx_vhosts`, `ssl_name` is mandatory. This role will search in `nginx_ssl_pairs` with vhost `name` (first in list if it's a list).
|
||||||
|
|
||||||
Diffie-Hellman
|
Diffie-Hellman
|
||||||
--------------
|
--------------
|
||||||
@@ -48,6 +49,9 @@ nginx_vhosts;
|
|||||||
proto: ['http', 'https']
|
proto: ['http', 'https']
|
||||||
template: '_base'
|
template: '_base'
|
||||||
ssl_name: 'mysuperkey'
|
ssl_name: 'mysuperkey'
|
||||||
|
- name: 'test-ssl2.local'
|
||||||
|
proto: ['http', 'https']
|
||||||
|
template: '_base'
|
||||||
|
|
||||||
nginx_ssl_pairs:
|
nginx_ssl_pairs:
|
||||||
- name: mysuperkey
|
- name: mysuperkey
|
||||||
@@ -59,5 +63,15 @@ nginx_ssl_pairs:
|
|||||||
-----BEGIN CERTIFICATE-----
|
-----BEGIN CERTIFICATE-----
|
||||||
....(snip)....
|
....(snip)....
|
||||||
-----END CERTIFICATE-----
|
-----END CERTIFICATE-----
|
||||||
|
- name: test-ssl2.local
|
||||||
|
key: |
|
||||||
|
-----BEGIN RSA PRIVATE KEY-----
|
||||||
|
....(snip)....
|
||||||
|
-----END RSA PRIVATE KEY-----
|
||||||
|
cert: |
|
||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
....(snip)....
|
||||||
|
-----END CERTIFICATE-----
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ Upstream params
|
|||||||
- `name`: upstream name. Can be use in vhost with *proxy_pass http://upstream_name*
|
- `name`: upstream name. Can be use in vhost with *proxy_pass http://upstream_name*
|
||||||
- `params`: list of param (hash, zone...)
|
- `params`: list of param (hash, zone...)
|
||||||
- `servers`: each upstream MUST have at least 1 server
|
- `servers`: each upstream MUST have at least 1 server
|
||||||
|
- `state`: Optional. Can be 'absent' or 'present'
|
||||||
|
|
||||||
Server params
|
Server params
|
||||||
-------------
|
-------------
|
||||||
@@ -38,4 +39,5 @@ nginx_upstreams:
|
|||||||
max_conns: 150
|
max_conns: 150
|
||||||
weight: 10
|
weight: 10
|
||||||
down: false
|
down: false
|
||||||
|
state: 'present'
|
||||||
```
|
```
|
||||||
|
|||||||
14
doc/vhost.md
14
doc/vhost.md
@@ -10,23 +10,26 @@ Common
|
|||||||
|
|
||||||
- `name`: (M) Domain or list of domain used.
|
- `name`: (M) Domain or list of domain used.
|
||||||
- `template`: (D) template used to create vhost. Optional if you set `delete` to true or using `redirect_tor`.
|
- `template`: (D) template used to create vhost. Optional if you set `delete` to true or using `redirect_tor`.
|
||||||
- `filename`: (O) Specify filename in /etc/nginx/sites-*. Do NOT specify default (reserved keyword).
|
- `filename`: (O) Specify filename in /etc/nginx/sites-*. Do NOT specify default (reserved keyword). It will be used for log filenames and directories creation.
|
||||||
- `enable`: (O) Enable the vhost (default is true)
|
- `state`: (O) Vhost status. Can be "present" (default), "absent" and "disabled".
|
||||||
- `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
|
||||||
- `redirect_to`: (O) Redirect all requests to this domain. Please set scheme (http:// or https:// or $sheme).
|
- `redirect_to`: (O) Redirect all requests to this domain. Please set scheme (http:// or https:// or $sheme).
|
||||||
- `headers`: (O) Set additionals header as key/value list. You can append "always" to the value. Show [nginx doc](http://nginx.org/en/docs/http/ngx_http_headers_module.html).
|
- `headers`: (O) Set additionals header as key/value list. You can append "always" to the value. Show [nginx doc](http://nginx.org/en/docs/http/ngx_http_headers_module.html).
|
||||||
- `redirect_to_code`: Redirect code (default: 302)
|
- `redirect_to_code`: Redirect code (default: 302)
|
||||||
- `redirect_https`: (O) Boolean. Redirect HTTP to HTTPS. If "true", you _MUST_ set `proto` to ```['https']```.
|
- `redirect_https`: (O) Boolean. Redirect HTTP to HTTPS. If "true", you _MUST_ set `proto` to ```['https']```.
|
||||||
- `location`: (O) Add new custom locations (it does not overwrite!)
|
- `location`: (O) Add new custom locations (it does not overwrite!)
|
||||||
|
- `location_order`: (O) Due to non preditive `location` order, you can provide the good order (see test-location.local in [tests/test.yml](../tests/test.yml)).
|
||||||
- `more`: (O) Add more custom infos.
|
- `more`: (O) Add more custom infos.
|
||||||
- `upstream_params`: (O) Add upstream params (useful when you want to pass variables to PHP)
|
- `upstream_params`: (O) Add upstream params (useful when you want to pass variables to PHP)
|
||||||
- `override_try_files`: (O) overrides default try\_files defined in template
|
- `override_try_files`: (O) overrides default try\_files defined in template
|
||||||
- `manage_local_content`: (O) Boolean. Set to false if you do not want to manage local content (images, css...). This option is useless if you use `_proxy` template or `redirect_to` feature.
|
- `manage_local_content`: (O) Boolean. Set to false if you do not want to manage local content (images, css...). This option is useless if you use `_proxy` template or `redirect_to` feature.
|
||||||
- `htpasswd`: (O) References name key in `nginx_htpasswd`. Enable auth basic on all vhost.
|
- `htpasswd`: (O) References name key in `nginx_htpasswd`. Enable auth basic on all vhost.
|
||||||
- `proto`: (O) list of protocol used. Default is a list with "http". If you need http and https, you must set a list with "http" and "https". You can only set "https" without http support.
|
- `proto`: (O) list of protocol used. Default is a list with "http". If you need http and https, you must set a list with "http" and "https". You can only set "https" without http support.
|
||||||
- `ssl_name`: (D) name of the key used when using TLS/SSL. Mandatory when `proto` contains "https"
|
- `ssl_name`: (D) name of the key used when using TLS/SSL. Optional when `proto` contains "https". If you don't set this value, it will search by `name`.
|
||||||
- `ssl_template` (O) "strong" (default) or "legacy". You can disable SSL helpers and add your own directives by setting "false".
|
- `ssl_template` (O) "strong" (default) or "legacy". You can disable SSL helpers and add your own directives by setting "false".
|
||||||
|
- `php_version` (O) Sepecify PHP version (5 or 7)
|
||||||
|
- `http_proxy_protocol_port` (O) Enable proxy protocol on http port.
|
||||||
|
- `https_proxy_protocol_port` (O) Enable proxy protocol on https port.
|
||||||
|
|
||||||
(O): Optional
|
(O): Optional
|
||||||
(M): Mandatory
|
(M): Mandatory
|
||||||
@@ -40,6 +43,7 @@ Templates
|
|||||||
- `_dokuwiki`
|
- `_dokuwiki`
|
||||||
- `_redirect`: should not be called explicitly
|
- `_redirect`: should not be called explicitly
|
||||||
- `_nagios3`: access to Nagios3 (be careful: you need to install [fcgiwrap](https://packages.debian.org/jessie/fcgiwrap))
|
- `_nagios3`: access to Nagios3 (be careful: you need to install [fcgiwrap](https://packages.debian.org/jessie/fcgiwrap))
|
||||||
|
- `_owncloud`: access to Owncloud (note: you must set `nginx_apt_package` to //nginx-extras//) **UNSTABLE**
|
||||||
- `_phalcon`: Phalcon PHP Framework
|
- `_phalcon`: Phalcon PHP Framework
|
||||||
- `_php`: PHP base template. Can work with many frameworks/tools
|
- `_php`: PHP base template. Can work with many frameworks/tools
|
||||||
- `_php_index`: Same as above. But you can only run index.php
|
- `_php_index`: Same as above. But you can only run index.php
|
||||||
|
|||||||
@@ -7,3 +7,7 @@
|
|||||||
|
|
||||||
- name: real-reload nginx
|
- name: real-reload nginx
|
||||||
service: name=nginx state=reloaded
|
service: name=nginx state=reloaded
|
||||||
|
|
||||||
|
- name: restart nginx freebsd
|
||||||
|
service: name=nginx state=restarted
|
||||||
|
when: ansible_distribution == "FreeBSD"
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ galaxy_info:
|
|||||||
platforms:
|
platforms:
|
||||||
- name: Debian
|
- name: Debian
|
||||||
versions:
|
versions:
|
||||||
- wheezy
|
|
||||||
- jessie
|
- jessie
|
||||||
- name: FreeBSD
|
- name: FreeBSD
|
||||||
versions:
|
versions:
|
||||||
|
|||||||
@@ -19,3 +19,16 @@
|
|||||||
dest="{{ nginx_etc_dir }}/conf.d/custom.conf"
|
dest="{{ nginx_etc_dir }}/conf.d/custom.conf"
|
||||||
notify: reload nginx
|
notify: reload nginx
|
||||||
|
|
||||||
|
- name: LINEINFILE | Fix path
|
||||||
|
lineinfile: >
|
||||||
|
regexp='{{ item.0.regexp }}'
|
||||||
|
line='{{ item.0.line }}'
|
||||||
|
dest='{{ item.1 }}'
|
||||||
|
with_nested:
|
||||||
|
-
|
||||||
|
- regexp: '^fastcgi_param SCRIPT_FILENAME'
|
||||||
|
line: 'fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;'
|
||||||
|
- regexp: '^fastcgi_param DOCUMENT_ROOT'
|
||||||
|
line: 'fastcgi_param DOCUMENT_ROOT $realpath_root;'
|
||||||
|
- [ '/etc/nginx/fastcgi_params', '/etc/nginx/fastcgi.conf' ]
|
||||||
|
when: nginx_fastcgi_fix_realpath
|
||||||
|
|||||||
16
tasks/dyn_modules.yml
Normal file
16
tasks/dyn_modules.yml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
- name: FAIL | If Dynamic module is not available
|
||||||
|
fail: msg="{{ item }} dynamic module is not available"
|
||||||
|
with_items: "{{ nginx_dyn_modules }}"
|
||||||
|
when: "'{{ item }}=dynamic' not in nginx_modules"
|
||||||
|
|
||||||
|
- name: APT | Install nginx modules
|
||||||
|
apt: >
|
||||||
|
pkg="libnginx-mod-{{ item | replace('_', '-') }}"
|
||||||
|
state=present
|
||||||
|
default_release={{ ansible_distribution_release + '-backports' if nginx_backports else ansible_distribution_release }}
|
||||||
|
with_items: "{{ nginx_dyn_modules }}"
|
||||||
|
when: ansible_distribution == 'Debian'
|
||||||
|
|
||||||
|
# TODO: manage freebsd
|
||||||
@@ -17,3 +17,4 @@
|
|||||||
- "{{ nginx_htpasswd }}"
|
- "{{ nginx_htpasswd }}"
|
||||||
- users
|
- users
|
||||||
when: item.0.state is not defined or item.0.state == 'present'
|
when: item.0.state is not defined or item.0.state == 'present'
|
||||||
|
no_log: true
|
||||||
|
|||||||
@@ -4,6 +4,14 @@
|
|||||||
apt: >
|
apt: >
|
||||||
update_cache=yes
|
update_cache=yes
|
||||||
cache_valid_time=3600
|
cache_valid_time=3600
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
|
- name: APT | Force OpenSSL from backports (fix dependency break)
|
||||||
|
apt: >
|
||||||
|
pkg=openssl
|
||||||
|
state=latest
|
||||||
|
default_release={{ ansible_distribution_release + '-backports' }}
|
||||||
|
when: nginx_backports
|
||||||
|
|
||||||
- name: APT | Install nginx and dependencies
|
- name: APT | Install nginx and dependencies
|
||||||
apt: >
|
apt: >
|
||||||
@@ -13,4 +21,3 @@
|
|||||||
|
|
||||||
- name: APT | Install python-passlib
|
- name: APT | Install python-passlib
|
||||||
apt: pkg=python-passlib state=present
|
apt: pkg=python-passlib state=present
|
||||||
|
|
||||||
|
|||||||
@@ -33,3 +33,14 @@
|
|||||||
copy: >
|
copy: >
|
||||||
content="proxy_set_header Host $http_host;\nproxy_set_header X-Real-IP $remote_addr;\nproxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header X-Forwarded-Proto $scheme;"
|
content="proxy_set_header Host $http_host;\nproxy_set_header X-Real-IP $remote_addr;\nproxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header X-Forwarded-Proto $scheme;"
|
||||||
dest="{{ nginx_etc_dir }}/proxy_params"
|
dest="{{ nginx_etc_dir }}/proxy_params"
|
||||||
|
|
||||||
|
- name: FILE | Create log directory
|
||||||
|
file: >
|
||||||
|
path={{ nginx_log_dir }}
|
||||||
|
owner={{ nginx_user }}
|
||||||
|
group=wheel
|
||||||
|
mode=0755
|
||||||
|
state=directory
|
||||||
|
|
||||||
|
- name: SERVICE | Enable nginx
|
||||||
|
service: name=nginx enabled=yes
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
|
|
||||||
- name: INCLUDE_VARS | Related to OS
|
- name: INCLUDE_VARS | Related to OS
|
||||||
include_vars: "{{ ansible_distribution }}.yml"
|
include_vars: "{{ ansible_distribution }}.yml"
|
||||||
|
|
||||||
@@ -10,6 +9,10 @@
|
|||||||
- name: INCLUDE | Prepare
|
- name: INCLUDE | Prepare
|
||||||
include: prepare.yml
|
include: prepare.yml
|
||||||
|
|
||||||
|
- name: INCLUDE | Manage dynamic modules
|
||||||
|
include: dyn_modules.yml
|
||||||
|
when: nginx_version.stdout | version_compare('1.9.11', 'ge')
|
||||||
|
|
||||||
- name: INCLUDE | Install
|
- name: INCLUDE | Install
|
||||||
include: config.yml
|
include: config.yml
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
changed_when: false
|
changed_when: false
|
||||||
|
|
||||||
- name: SHELL | Get module list
|
- name: SHELL | Get module list
|
||||||
shell: nginx -V 2>&1 | tr -- - '\n' | grep -A 1 with | grep _module | sed 's/_module[[:space:]]*//g' | sort
|
shell: nginx -V 2>&1 | tr -- - '\n' | grep -A 1 with | grep _module | sed -r 's/_module//g; s/\s+//g' | sort
|
||||||
args:
|
args:
|
||||||
executable: /bin/sh
|
executable: /bin/sh
|
||||||
register: shell_modules
|
register: shell_modules
|
||||||
@@ -19,6 +19,8 @@
|
|||||||
nginx_modules: "{{ shell_modules.stdout_lines }}"
|
nginx_modules: "{{ shell_modules.stdout_lines }}"
|
||||||
|
|
||||||
- name: FILE | Create folders
|
- name: FILE | Create folders
|
||||||
file: dest={{ item }} owner=root mode=0755 state=directory
|
file: dest="{{ item.dir }}" owner="{{ item.owner }}" mode="{{ item.mode }}" state=directory
|
||||||
with_items: "{{ nginx_dirs }}"
|
with_items: "{{ nginx_dirs }}"
|
||||||
|
|
||||||
|
- name: FILE | Create ansible facts dir
|
||||||
|
file: path=/etc/ansible/facts.d state=directory
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
creates: "{{ nginx_dh_path }}"
|
creates: "{{ nginx_dh_path }}"
|
||||||
when: nginx_dh is not string
|
when: nginx_dh is not string
|
||||||
notify: reload nginx
|
notify: reload nginx
|
||||||
|
async: 1000
|
||||||
|
register: dh
|
||||||
|
|
||||||
- name: COPY | Deploy DH file from vars
|
- name: COPY | Deploy DH file from vars
|
||||||
copy: >
|
copy: >
|
||||||
@@ -20,20 +22,31 @@
|
|||||||
state=directory
|
state=directory
|
||||||
with_items: "{{ nginx_ssl_pairs }}"
|
with_items: "{{ nginx_ssl_pairs }}"
|
||||||
when: item.dest_key is not defined or item.dest_cert is not defined
|
when: item.dest_key is not defined or item.dest_cert is not defined
|
||||||
|
no_log: true
|
||||||
|
|
||||||
- name: COPY | Deploy SSL keys
|
- name: COPY | Deploy SSL keys
|
||||||
copy: >
|
copy: >
|
||||||
content="{{ item.key }}"
|
content="{{ item.key }}"
|
||||||
dest="{{ nginx_ssl_dir + '/' + item.name + '/' + item.name + '.key' if item.dest_key is not defined else item.dest_key }}"
|
dest="{{ nginx_ssl_dir + '/' + item.name + '/' + item.name + '.key' if item.dest_key is not defined else item.dest_key }}"
|
||||||
|
mode=0640
|
||||||
with_items: "{{ nginx_ssl_pairs }}"
|
with_items: "{{ nginx_ssl_pairs }}"
|
||||||
when: item.key is defined
|
when: item.key is defined
|
||||||
notify: reload nginx
|
notify: reload nginx
|
||||||
|
no_log: true
|
||||||
|
|
||||||
- name: COPY | Deploy SSL certs
|
- name: COPY | Deploy SSL certs
|
||||||
copy: >
|
copy: >
|
||||||
content="{{ item.cert }}"
|
content="{{ item.cert }}"
|
||||||
dest="{{ nginx_ssl_dir + '/' + item.name + '/' + item.name + '.crt' if item.dest_cert is not defined else item.dest_cert }}"
|
dest="{{ nginx_ssl_dir + '/' + item.name + '/' + item.name + '.crt' if item.dest_cert is not defined else item.dest_cert }}"
|
||||||
|
mode=0644
|
||||||
with_items: "{{ nginx_ssl_pairs }}"
|
with_items: "{{ nginx_ssl_pairs }}"
|
||||||
when: item.cert is defined
|
when: item.cert is defined
|
||||||
notify: reload nginx
|
notify: reload nginx
|
||||||
|
no_log: true
|
||||||
|
|
||||||
|
- name: Check DH command status
|
||||||
|
async_status: jid={{ dh.ansible_job_id }}
|
||||||
|
register: job_result
|
||||||
|
until: job_result.finished
|
||||||
|
retries: 30
|
||||||
|
when: nginx_dh is not string
|
||||||
|
|||||||
@@ -1,10 +1,15 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
|
- name: SET_FACT | Backward compatibility with old version of this role
|
||||||
|
set_fact: >
|
||||||
|
nginx_php56: true
|
||||||
|
when: nginx_php is defined and nginx_php
|
||||||
|
|
||||||
- name: TEMPLATE | Deploy PHP upstream to Nginx
|
- name: TEMPLATE | Deploy PHP upstream to Nginx
|
||||||
template: >
|
template: >
|
||||||
src=etc/nginx/upstream/php.conf.j2
|
src=etc/nginx/upstream/php.conf.j2
|
||||||
dest="{{ nginx_etc_dir }}/conf.d/php.conf"
|
dest="{{ nginx_etc_dir }}/conf.d/php.conf"
|
||||||
when: nginx_php
|
when: nginx_php56 or nginx_php70
|
||||||
notify: reload nginx
|
notify: reload nginx
|
||||||
|
|
||||||
- name: TEMPLATE | Deploy other upstreams
|
- name: TEMPLATE | Deploy other upstreams
|
||||||
@@ -12,4 +17,13 @@
|
|||||||
src=etc/nginx/upstream/upstream.conf.j2
|
src=etc/nginx/upstream/upstream.conf.j2
|
||||||
dest={{ nginx_etc_dir }}/conf.d/upstream-{{ item.name }}.conf
|
dest={{ nginx_etc_dir }}/conf.d/upstream-{{ item.name }}.conf
|
||||||
with_items: "{{ nginx_upstreams }}"
|
with_items: "{{ nginx_upstreams }}"
|
||||||
|
when: item.state is not defined or item.state == 'present'
|
||||||
|
notify: reload nginx
|
||||||
|
|
||||||
|
- name: FILE | Delete other upstreams
|
||||||
|
file: >
|
||||||
|
path={{ nginx_etc_dir }}/conf.d/upstream-{{ item.name }}.conf
|
||||||
|
state=absent
|
||||||
|
with_items: "{{ nginx_upstreams }}"
|
||||||
|
when: item.state is defined and item.state == 'absent'
|
||||||
notify: reload nginx
|
notify: reload nginx
|
||||||
|
|||||||
@@ -5,14 +5,6 @@
|
|||||||
when: item.filename is defined and item.filename == 'default'
|
when: item.filename is defined and item.filename == 'default'
|
||||||
with_items: "{{ nginx_vhosts }}"
|
with_items: "{{ nginx_vhosts }}"
|
||||||
|
|
||||||
- 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: FAIL | Check HTTPS redir and proto
|
- name: FAIL | Check HTTPS redir and proto
|
||||||
fail: msg="You can't have HTTP proto and HTTPS redirection at the same time"
|
fail: msg="You can't have HTTP proto and HTTPS redirection at the same time"
|
||||||
when: >
|
when: >
|
||||||
@@ -27,7 +19,7 @@
|
|||||||
|
|
||||||
- name: FILE | Create root public folders (foreach nginx_vhosts)
|
- 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.filename | default(item.name if item.name is string else item.name[0]) }}/public
|
||||||
state=directory
|
state=directory
|
||||||
owner={{ item.owner | default(nginx_user) }}
|
owner={{ item.owner | default(nginx_user) }}
|
||||||
group={{ item.group | default(nginx_user) }}
|
group={{ item.group | default(nginx_user) }}
|
||||||
@@ -36,7 +28,7 @@
|
|||||||
when: >
|
when: >
|
||||||
item.root is not defined and
|
item.root is not defined and
|
||||||
(item.template is defined and item.template not in nginx_templates_no_dir) and
|
(item.template is defined and item.template not in nginx_templates_no_dir) and
|
||||||
(item.delete is not defined or not item.delete) and
|
(item.state is not defined or not item.state != 'absent') and
|
||||||
item.redirect_to is not defined
|
item.redirect_to is not defined
|
||||||
|
|
||||||
- name: TEMPLATE | Create vhosts
|
- name: TEMPLATE | Create vhosts
|
||||||
@@ -44,14 +36,16 @@
|
|||||||
src=etc/nginx/sites-available/{{ item.template if item.redirect_to is not defined else '_redirect' }}.j2
|
src=etc/nginx/sites-available/{{ item.template if item.redirect_to is not defined else '_redirect' }}.j2
|
||||||
dest={{ nginx_etc_dir }}/sites-available/{{ item.filename | default(item.name if item.name is string else item.name[0]) }}
|
dest={{ nginx_etc_dir }}/sites-available/{{ item.filename | default(item.name if item.name is string else item.name[0]) }}
|
||||||
with_items: "{{ nginx_vhosts }}"
|
with_items: "{{ nginx_vhosts }}"
|
||||||
notify: reload nginx
|
notify: ['reload nginx', 'restart nginx freebsd']
|
||||||
when: item.delete is not defined or not item.delete
|
when: item.state is not defined or item.state != 'absent'
|
||||||
|
|
||||||
- name: FILE | Delete vhosts
|
- name: FILE | Delete vhosts
|
||||||
file: path={{ nginx_etc_dir }}/sites-available/{{ item.filename | default(item.name if item.name is string else item.name[0]) }} state=absent
|
file: path={{ nginx_etc_dir }}/{{ item.1 }}/{{ item.0.filename | default(item.0.name if item.0.name is string else item.0.name[0]) }} state=absent
|
||||||
with_items: "{{ nginx_vhosts }}"
|
with_nested:
|
||||||
notify: reload nginx
|
- "{{ nginx_vhosts }}"
|
||||||
when: item.delete is defined and item.delete
|
- ['sites-available', 'sites-enabled']
|
||||||
|
notify: ['reload nginx', 'restart nginx freebsd']
|
||||||
|
when: item.state is defined and item.state == 'absent'
|
||||||
|
|
||||||
- name: FILE | Enable vhosts
|
- name: FILE | Enable vhosts
|
||||||
file: >
|
file: >
|
||||||
@@ -59,23 +53,21 @@
|
|||||||
dest={{ nginx_etc_dir }}/sites-enabled/{{ 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]) }}
|
||||||
state=link
|
state=link
|
||||||
with_items: "{{ nginx_vhosts }}"
|
with_items: "{{ nginx_vhosts }}"
|
||||||
notify: reload nginx
|
notify: ['reload nginx', 'restart nginx freebsd']
|
||||||
when: >
|
when: >
|
||||||
((item.enable is not defined) or
|
item.state is not defined or item.state == 'present'
|
||||||
(item.enable is defined and item.enable)) and
|
|
||||||
(item.delete is not defined or not item.delete)
|
|
||||||
|
|
||||||
- name: FILE | Disable vhosts
|
- name: FILE | Disable vhosts
|
||||||
file: path={{ nginx_etc_dir}}/sites-enabled/{{ item.filename | default(item.name if item.name is string else item.name[0]) }} state=absent
|
file: path={{ nginx_etc_dir}}/sites-enabled/{{ item.filename | default(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', 'restart nginx freebsd']
|
||||||
when: (item.enable is defined and not item.enable) or (item.delete is defined and item.delete)
|
when: item.state is defined and item.state == 'disabled'
|
||||||
|
|
||||||
- name: FILE | Delete default vhost when explicitely defined
|
- name: FILE | Delete default vhost when explicitely defined
|
||||||
file: >
|
file: >
|
||||||
path={{ nginx_etc_dir }}/sites-enabled/default
|
path={{ nginx_etc_dir }}/sites-enabled/default
|
||||||
state=absent
|
state=absent
|
||||||
notify: reload nginx
|
notify: ['reload nginx', 'restart nginx freebsd']
|
||||||
when: nginx_default_vhost is not none
|
when: nginx_default_vhost is not none
|
||||||
|
|
||||||
- name: FILE | Auto set default vhost
|
- name: FILE | Auto set default vhost
|
||||||
@@ -83,5 +75,16 @@
|
|||||||
src={{ nginx_etc_dir }}/sites-available/default
|
src={{ nginx_etc_dir }}/sites-available/default
|
||||||
dest={{ nginx_etc_dir }}/sites-enabled/default
|
dest={{ nginx_etc_dir }}/sites-enabled/default
|
||||||
state=link
|
state=link
|
||||||
notify: reload nginx
|
notify: ['reload nginx', 'restart nginx freebsd']
|
||||||
when: nginx_default_vhost is none
|
when: nginx_default_vhost is none
|
||||||
|
|
||||||
|
- name: TEMPLATE | Deploy facts
|
||||||
|
template:
|
||||||
|
src=etc/ansible/facts.d/nginx.fact.j2
|
||||||
|
dest=/etc/ansible/facts.d/nginx.fact
|
||||||
|
mode=0644
|
||||||
|
register: fact
|
||||||
|
|
||||||
|
- name: SETUP
|
||||||
|
action: setup
|
||||||
|
when: fact.changed
|
||||||
|
|||||||
4
templates/etc/ansible/facts.d/nginx.fact.j2
Normal file
4
templates/etc/ansible/facts.d/nginx.fact.j2
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"fact_nginx_vhosts":
|
||||||
|
{{ nginx_vhosts | to_nice_json(indent=8) }}
|
||||||
|
}
|
||||||
@@ -5,6 +5,11 @@
|
|||||||
user {{ nginx_user }};
|
user {{ nginx_user }};
|
||||||
worker_processes {{ nginx_worker_processes }};
|
worker_processes {{ nginx_worker_processes }};
|
||||||
pid {{ nginx_pid }};
|
pid {{ nginx_pid }};
|
||||||
|
{% if nginx_version.stdout | version_compare('1.9.11', 'ge') %}
|
||||||
|
{% for module in nginx_dyn_modules -%}
|
||||||
|
load_module "modules/ngx_{{ module }}_module.so";
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
events {
|
events {
|
||||||
worker_connections {{ nginx_events_worker_connections }};
|
worker_connections {{ nginx_events_worker_connections }};
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
{% set __proto = item.proto | default(['http']) %}
|
{% set __proto = item.proto | default(['http']) %}
|
||||||
{% set __main_name = item.name if item.name is string else item.name[0] %}
|
{% set __main_name = item.filename | default(item.name if item.name is string else item.name[0]) %}
|
||||||
{% set __listen = item.listen | default(['80']) %}
|
{% set __listen = item.listen | default([80]) %}
|
||||||
{% set __listen_ssl = item.listen_ssl | default(['443']) %}
|
{% set __listen_ssl = item.listen_ssl | default([443]) %}
|
||||||
|
{% set __http_proxy_protocol_port = item.http_proxy_protocol_port | default([]) %}
|
||||||
|
{% set __https_proxy_protocol_port = item.https_proxy_protocol_port | default([]) %}
|
||||||
{% set __location = item.location | default({}) %}
|
{% set __location = item.location | default({}) %}
|
||||||
{% set __headers = item.headers | default({'X-Frame-Options': 'DENY always', 'X-Content-Type-Options': 'nosniff always' }) %}
|
{% set __headers = item.headers | default({'X-Frame-Options': 'DENY always', 'X-Content-Type-Options': 'nosniff always' }) %}
|
||||||
|
{% set __ssl_name = item.ssl_name | default(item.name if item.name is string else item.name[0]) %}
|
||||||
|
{% set __location_order = item.location_order | default(__location.keys()) %}
|
||||||
{% macro htpasswd(htpasswd_name, indent=1) -%}
|
{% macro htpasswd(htpasswd_name, indent=1) -%}
|
||||||
{% for ht in nginx_htpasswd if ht.name == htpasswd_name %}
|
{% for ht in nginx_htpasswd if ht.name == htpasswd_name %}
|
||||||
{{ "\t" * indent }}auth_basic "{{ ht.description }}";
|
{{ "\t" * indent }}auth_basic "{{ ht.description }}";
|
||||||
@@ -26,19 +30,19 @@
|
|||||||
server {
|
server {
|
||||||
{% if 'http' in __proto %}
|
{% if 'http' in __proto %}
|
||||||
{% for port in __listen %}
|
{% for port in __listen %}
|
||||||
listen {{ port }}{% if nginx_default_vhost == __main_name %} default_server{% endif %};
|
listen {{ port }}{% if nginx_default_vhost == __main_name %} default_server{% endif %}{% if port | int in __http_proxy_protocol_port %} proxy_protocol{% endif %};
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if 'https' in __proto %}
|
{% if 'https' in __proto %}
|
||||||
{% for port in __listen_ssl %}
|
{% for port in __listen_ssl %}
|
||||||
listen {{ port }}{% if nginx_default_vhost_ssl == __main_name %} default_server{% endif %} ssl{% if nginx_auto_config_httpv2 and 'http_v2' in nginx_modules %} http2{% endif %};
|
listen {{ port }}{% if nginx_default_vhost_ssl == __main_name %} default_server{% endif %} ssl{% if nginx_auto_config_httpv2 and 'http_v2' in nginx_modules %} http2{% endif %}{% if port | int in __https_proxy_protocol_port %} proxy_protocol{% endif %};
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{{ ssl(item.ssl_name) }}
|
{{ ssl(__ssl_name) }}
|
||||||
{% if item.ssl_template is not defined or item.ssl_template != false %}
|
{% if item.ssl_template is not defined or item.ssl_template != false %}
|
||||||
include {{ nginx_helper_dir + '/ssl-' + item.ssl_template | default('strong') }};
|
include {{ nginx_helper_dir + '/ssl-' + item.ssl_template | default('strong') }};
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
server_name {% if item.name is string %}{{ item.name }}{% else %}{{ item.name | join(' ') }}{% endif %};
|
server_name {% if item.name is string %}{{ item.name }}{% else %}{{ "\n\t\t" }}{{ item.name | join("\n\t\t") }}{% endif %};
|
||||||
{% block root %}
|
{% block root %}
|
||||||
{% if item.root is defined %}
|
{% if item.root is defined %}
|
||||||
root {{ item.root }};
|
root {{ item.root }};
|
||||||
@@ -50,11 +54,13 @@ server {
|
|||||||
index {{ item.index | default('index.html index.htm') }};
|
index {{ item.index | default('index.html index.htm') }};
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block template_more %}
|
||||||
{% if item.more is defined and item.more is iterable %}
|
{% if item.more is defined and item.more is iterable %}
|
||||||
{% for line in item.more %}
|
{% for line in item.more %}
|
||||||
{{ line }}
|
{{ line }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
{% if item.htpasswd is defined %}
|
{% if item.htpasswd is defined %}
|
||||||
{{ htpasswd(item.htpasswd, 1) }}
|
{{ htpasswd(item.htpasswd, 1) }}
|
||||||
@@ -81,6 +87,20 @@ server {
|
|||||||
{% block template_custom_location %}
|
{% block template_custom_location %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% if __location_order | length > 0 %}
|
||||||
|
# --> Custom locations
|
||||||
|
{% for location in __location_order %}
|
||||||
|
location {{ location }} {
|
||||||
|
{% set opts = __location[location] %}
|
||||||
|
{% for opt in opts %}
|
||||||
|
{% if opt.htpasswd is defined %}{{ htpasswd(opt.htpasswd, 2) }}{% else %}
|
||||||
|
{{ opt }}
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
}
|
||||||
|
{% endfor %} # <-- Custom locations
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% block template_local_content %}
|
{% block template_local_content %}
|
||||||
{% if item.manage_local_content is not defined or item.manage_local_content %}
|
{% if item.manage_local_content is not defined or item.manage_local_content %}
|
||||||
location ~ /\.ht {
|
location ~ /\.ht {
|
||||||
@@ -100,19 +120,6 @@ server {
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% if __location is iterable and __location | length > 0 %}
|
|
||||||
# --> Custom locations
|
|
||||||
{% for location, opts in __location.iteritems() %}
|
|
||||||
location {{ location }} {
|
|
||||||
{% for opt in opts %}
|
|
||||||
{% if opt.htpasswd is defined %}{{ htpasswd(opt.htpasswd, 2) }}{% else %}
|
|
||||||
{{ opt }}
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
|
||||||
}
|
|
||||||
{% endfor %} # <-- Custom locations
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if item.use_access_log is defined %}
|
{% if item.use_access_log is defined %}
|
||||||
{% if item.use_access_log %}
|
{% if item.use_access_log %}
|
||||||
access_log {{ nginx_log_dir }}/{{ __main_name }}_access.log combined;
|
access_log {{ nginx_log_dir }}/{{ __main_name }}_access.log combined;
|
||||||
@@ -135,10 +142,10 @@ server {
|
|||||||
#
|
#
|
||||||
server {
|
server {
|
||||||
{% for port in __listen %}
|
{% for port in __listen %}
|
||||||
listen {{ port }};
|
listen {{ port }}{% if nginx_default_vhost == __main_name %} default_server{% endif %}{% if port | int in __http_proxy_protocol_port %} proxy_protocol{% endif %};
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
server_name {% if item.name is string %}{{ item.name }}{% else %}{{ item.name | join(' ') }}{% endif %};
|
server_name {% if item.name is string %}{{ item.name }}{% else %}{{ "\n\t\t" }}{{ item.name | join("\n\t\t") }}{% endif %};
|
||||||
return 301 https://{{ __main_name }}{% if '443' not in __listen_ssl %}:__listen_ssl[0]{% endif %}$request_uri;
|
return 301 https://{{ __main_name }}{% if '443' not in __listen_ssl %}:{{ __listen_ssl[0] }}{% endif %}$request_uri;
|
||||||
}
|
}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
@@ -149,9 +156,9 @@ server {
|
|||||||
#
|
#
|
||||||
server {
|
server {
|
||||||
{% for port in __listen %}
|
{% for port in __listen %}
|
||||||
listen {{ port }};
|
listen {{ port }}{% if port | int in __http_proxy_protocol_port %} proxy_protocol{% endif %};
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
server_name {{ item.redirect_from | join(' ') }};
|
server_name {% if item.redirect_from is string %}{{ item.redirect_from }}{% else %}{{ "\n\t\t" }}{{ item.redirect_from | join("\n\t\t") }}{% endif %};
|
||||||
return 301 $scheme://{{ __main_name }}$request_uri;
|
return 301 $scheme://{{ __main_name }}$request_uri;
|
||||||
}
|
}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
{% extends "_base.j2" %}
|
{% extends "_php.j2" %}
|
||||||
|
|
||||||
{% block root %}
|
{% block root %}
|
||||||
root {{ nginx_nagios_root }};
|
root {{ nginx_nagios_root }};
|
||||||
@@ -56,7 +56,7 @@
|
|||||||
fastcgi_param REMOTE_USER $remote_user;
|
fastcgi_param REMOTE_USER $remote_user;
|
||||||
}
|
}
|
||||||
location ~ \.php$ {
|
location ~ \.php$ {
|
||||||
fastcgi_pass php;
|
fastcgi_pass {{ php_upstream }};
|
||||||
fastcgi_index index.php;
|
fastcgi_index index.php;
|
||||||
{% if nginx_version.stdout | version_compare('1.6.1', 'lt') %}
|
{% if nginx_version.stdout | version_compare('1.6.1', 'lt') %}
|
||||||
include fastcgi_params;
|
include fastcgi_params;
|
||||||
|
|||||||
87
templates/etc/nginx/sites-available/_owncloud.j2
Normal file
87
templates/etc/nginx/sites-available/_owncloud.j2
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
{% extends "_php.j2" %}
|
||||||
|
|
||||||
|
{% block root %}
|
||||||
|
root {{ nginx_owncloud_root }};
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block template_index %}
|
||||||
|
index index.php;
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block template_more %}
|
||||||
|
error_page 403 /core/templates/403.php;
|
||||||
|
error_page 404 /core/templates/404.php;
|
||||||
|
gzip off;
|
||||||
|
client_max_body_size 10G;
|
||||||
|
fastcgi_buffers 64 4K;
|
||||||
|
rewrite ^/caldav(.*)$ /remote.php/caldav$1 redirect;
|
||||||
|
rewrite ^/carddav(.*)$ /remote.php/carddav$1 redirect;
|
||||||
|
rewrite ^/webdav(.*)$ /remote.php/webdav$1 redirect;
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block template_headers %}
|
||||||
|
add_header X-XSS-Protection "1; mode=block";
|
||||||
|
add_header X-Robots-Tag none;
|
||||||
|
add_header X-Content-Type-Options nosniff;
|
||||||
|
add_header X-Download-Options noopen;
|
||||||
|
add_header X-Permitted-Cross-Domain-Policies none;
|
||||||
|
add_header X-Frame-Options SAMEORIGIN;
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block template_try_files %}
|
||||||
|
try_files $uri $uri/ =404;
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block template_upstream_location %}
|
||||||
|
location ~ /remote.php {
|
||||||
|
dav_methods PUT DELETE MKCOL COPY MOVE;
|
||||||
|
dav_ext_methods PROPFIND OPTIONS;
|
||||||
|
fastcgi_pass {{ php_upstream }};
|
||||||
|
fastcgi_param HOME {{ nginx_owncloud_root }};
|
||||||
|
fastcgi_param HTTP_HOME {{ nginx_owncloud_root }};
|
||||||
|
fastcgi_param PATH /usr/local/bin:/usr/bin:/bin;
|
||||||
|
fastcgi_param modHeadersAvailable true;
|
||||||
|
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
||||||
|
{% if nginx_version.stdout | version_compare('1.6.1', 'lt') %}
|
||||||
|
include fastcgi_params;
|
||||||
|
{% else %}
|
||||||
|
include fastcgi.conf;
|
||||||
|
{% endif %}
|
||||||
|
}
|
||||||
|
|
||||||
|
location ~ \.php(?:$|/) {
|
||||||
|
fastcgi_pass {{ php_upstream }};
|
||||||
|
fastcgi_index index.php;
|
||||||
|
fastcgi_param HOME {{ nginx_owncloud_root }};
|
||||||
|
fastcgi_param HTTP_HOME {{ nginx_owncloud_root }};
|
||||||
|
fastcgi_param PATH /usr/local/bin:/usr/bin:/bin;
|
||||||
|
fastcgi_param modHeadersAvailable true;
|
||||||
|
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
||||||
|
{% if nginx_version.stdout | version_compare('1.6.1', 'lt') %}
|
||||||
|
include fastcgi_params;
|
||||||
|
{% else %}
|
||||||
|
include fastcgi.conf;
|
||||||
|
{% endif %}
|
||||||
|
}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block template_local_content %}
|
||||||
|
location ~* \.(?:css|js)$ {
|
||||||
|
try_files $uri /index.php$is_args$args;
|
||||||
|
expires 2h;
|
||||||
|
}
|
||||||
|
|
||||||
|
location ~* \.(?:jpg|jpeg|gif|bmp|ico|png|swf)$ {
|
||||||
|
expires 2d;
|
||||||
|
}
|
||||||
|
|
||||||
|
location = /robots.txt {
|
||||||
|
allow all;
|
||||||
|
log_not_found off;
|
||||||
|
access_log off;
|
||||||
|
}
|
||||||
|
|
||||||
|
location ~ ^/(?:\.ht|data|config|db_structure\.xml|README){
|
||||||
|
deny all;
|
||||||
|
}
|
||||||
|
{% endblock %}
|
||||||
@@ -1,4 +1,24 @@
|
|||||||
{% extends "_base.j2" %}
|
{% extends "_base.j2" %}
|
||||||
|
|
||||||
|
{% macro phpv(version) %}
|
||||||
|
{% if version == 56 or version == "56" or version == "5.6" %}
|
||||||
|
{{ nginx_upstream_php56 -}}
|
||||||
|
{% elif version == 70 or version == "70" or version == "7.0" %}
|
||||||
|
{{ nginx_upstream_php70 -}}
|
||||||
|
{% else %}
|
||||||
|
{# Hack... define another upstream #}
|
||||||
|
{{ version -}}
|
||||||
|
{% endif %}
|
||||||
|
{%- endmacro -%}
|
||||||
|
|
||||||
|
{% if item.php_version is defined %}
|
||||||
|
{% set php_upstream = phpv(item.php_version) %}
|
||||||
|
{% elif nginx_php56 %}
|
||||||
|
{% set php_upstream = phpv(56) %}
|
||||||
|
{% elif nginx_php70 %}
|
||||||
|
{% set php_upstream = phpv(70) %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% block template_index %}
|
{% block template_index %}
|
||||||
index {{ item.index | default('index.html index.htm index.php') }};
|
index {{ item.index | default('index.html index.htm index.php') }};
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -9,7 +29,7 @@
|
|||||||
|
|
||||||
{% block template_upstream_location %}
|
{% block template_upstream_location %}
|
||||||
location ~ \.php$ {
|
location ~ \.php$ {
|
||||||
fastcgi_pass php;
|
fastcgi_pass {{ php_upstream }};
|
||||||
fastcgi_index index.php;
|
fastcgi_index index.php;
|
||||||
{% if item.upstream_params is defined and item.upstream_params is iterable %}
|
{% if item.upstream_params is defined and item.upstream_params is iterable %}
|
||||||
{% for param in item.upstream_params %}
|
{% for param in item.upstream_params %}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
{% block template_upstream_location %}
|
{% block template_upstream_location %}
|
||||||
location = /index.php {
|
location = /index.php {
|
||||||
fastcgi_pass php;
|
fastcgi_pass {{ php_upstream }};
|
||||||
fastcgi_index index.php;
|
fastcgi_index index.php;
|
||||||
{% if item.upstream_params is defined and item.upstream_params is iterable %}
|
{% if item.upstream_params is defined and item.upstream_params is iterable %}
|
||||||
{% for param in item.upstream_params %}
|
{% for param in item.upstream_params %}
|
||||||
|
|||||||
@@ -3,3 +3,9 @@
|
|||||||
{% block template_try_files %}
|
{% block template_try_files %}
|
||||||
try_files $uri $uri/ /index.php?$args;
|
try_files $uri $uri/ /index.php?$args;
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block template_custom_location %}
|
||||||
|
location ~* /(?:uploads|files)/.*\.php$ {
|
||||||
|
deny all;
|
||||||
|
}
|
||||||
|
{% endblock %}
|
||||||
|
|||||||
@@ -2,8 +2,9 @@
|
|||||||
# {{ ansible_managed }}
|
# {{ ansible_managed }}
|
||||||
#
|
#
|
||||||
|
|
||||||
upstream php {
|
{% if nginx_php56 %}
|
||||||
{% for item in nginx_php_sockets %}
|
upstream {{ nginx_upstream_php56 }} {
|
||||||
|
{% for item in nginx_php56_sockets %}
|
||||||
{% if item.unix_socket is defined %}
|
{% if item.unix_socket is defined %}
|
||||||
server unix:{{ item.unix_socket }} weight={{ item.weight | default('1') }};
|
server unix:{{ item.unix_socket }} weight={{ item.weight | default('1') }};
|
||||||
{% else %}
|
{% else %}
|
||||||
@@ -12,4 +13,18 @@ upstream php {
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
{% if nginx_php70 %}
|
||||||
|
upstream {{ nginx_upstream_php70 }} {
|
||||||
|
{% for item in nginx_php70_sockets %}
|
||||||
|
{% if item.unix_socket is defined %}
|
||||||
|
server unix:{{ item.unix_socket }} weight={{ item.weight | default('1') }};
|
||||||
|
{% else %}
|
||||||
|
server {{ item.host }}:{{ item.port }} weight={{ item.weight | default('1') }} max_fails={{ item.max_fails | default('5') }} fail_timeout={{ item.fail_timeout | default('10s') }};
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
}
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
# vim:filetype=nginx
|
# vim:filetype=nginx
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
FROM williamyeh/ansible:debian8-onbuild
|
FROM williamyeh/ansible:debian8-onbuild
|
||||||
|
|
||||||
RUN apt-get update
|
RUN apt-get update
|
||||||
CMD ["sh", "tests/test.sh"]
|
CMD ["sh", "tests/travis.sh"]
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
FROM williamyeh/ansible:debian7-onbuild
|
|
||||||
|
|
||||||
RUN apt-get update
|
|
||||||
CMD ["sh", "tests/test.sh"]
|
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
- name: APT | Install web apps
|
- name: APT | Install web apps
|
||||||
apt: pkg={{ item }} state=present
|
apt: pkg={{ item }} state=present install_recommends=no
|
||||||
with_items:
|
with_items:
|
||||||
- nagios3
|
|
||||||
- backuppc
|
- backuppc
|
||||||
|
- nagios3
|
||||||
|
# - owncloud
|
||||||
|
|
||||||
- name: SERVICE | Ensure backuppc is started
|
- name: SERVICE | Ensure backuppc is started
|
||||||
service: name=backuppc state=started
|
service: name=backuppc state=started
|
||||||
|
|||||||
@@ -3,20 +3,45 @@
|
|||||||
- name: APT_REPOSITORY | Install backports
|
- name: APT_REPOSITORY | Install backports
|
||||||
apt_repository: repo='deb http://httpredir.debian.org/debian {{ ansible_distribution_release }}-backports main' state=present
|
apt_repository: repo='deb http://httpredir.debian.org/debian {{ ansible_distribution_release }}-backports main' state=present
|
||||||
|
|
||||||
|
- block:
|
||||||
|
- name: APT | Install DotDeb key
|
||||||
|
apt_key: url='http://www.dotdeb.org/dotdeb.gpg' state=present
|
||||||
|
- name: APT_REPOSITORY | Install dotdeb (PHP 7)
|
||||||
|
apt_repository: repo='deb http://packages.dotdeb.org {{ ansible_distribution_release }} all' state=present
|
||||||
|
- name: LINEFILEFILE | Dotdeb priority (prevent install nginx from dotdeb)
|
||||||
|
copy: >
|
||||||
|
content="Package: *\nPin: release o=packages.dotdeb.org\nPin-Priority: 100"
|
||||||
|
dest=/etc/apt/preferences
|
||||||
|
when: ansible_distribution_release == 'jessie' and dotdeb
|
||||||
|
|
||||||
- name: APT | Install needed packages
|
- name: APT | Install needed packages
|
||||||
apt: pkg={{ item }} update_cache=yes cache_valid_time=3600 state=present
|
apt: pkg={{ item }} update_cache=yes cache_valid_time=3600 state=present
|
||||||
with_items:
|
with_items:
|
||||||
- php5-fpm
|
|
||||||
- curl
|
- curl
|
||||||
- fcgiwrap
|
- fcgiwrap
|
||||||
|
- nghttp2
|
||||||
|
- strace
|
||||||
|
- vim
|
||||||
|
|
||||||
- name: APT | Install nghttp2
|
- name: APT | Install PHP5.6
|
||||||
apt: pkg=nghttp2 state=present
|
apt: pkg={{ item }} update_cache=yes cache_valid_time=3600 state=present
|
||||||
when: ansible_distribution_major_version | version_compare(8, 'ge')
|
|
||||||
|
|
||||||
- name: SERVICE | Force start services
|
|
||||||
service: name={{ item }} state=started
|
|
||||||
register: sf
|
|
||||||
with_items:
|
with_items:
|
||||||
- php5-fpm
|
- php5-fpm
|
||||||
- fcgiwrap
|
- php5-sqlite
|
||||||
|
when: nginx_php56
|
||||||
|
|
||||||
|
- name: APT | Install PHP7
|
||||||
|
apt: pkg={{ item }} update_cache=yes cache_valid_time=3600 state=present
|
||||||
|
with_items:
|
||||||
|
- php7.0-fpm
|
||||||
|
- php7.0-sqlite3
|
||||||
|
when: nginx_php70
|
||||||
|
|
||||||
|
- name: SERVICE | Force start services
|
||||||
|
service: name={{ item.name }} state=started
|
||||||
|
register: sf
|
||||||
|
with_items:
|
||||||
|
- { name: 'php5-fpm', cond: "{{ nginx_php56 }}" }
|
||||||
|
- { name: 'php7.0-fpm', cond: "{{ nginx_php70 }}" }
|
||||||
|
- { name: 'fcgiwrap', cond: true }
|
||||||
|
when: "{{ item.cond }}"
|
||||||
|
|||||||
@@ -4,7 +4,8 @@
|
|||||||
set_fact:
|
set_fact:
|
||||||
nginx_pkgng_package: 'nginx-devel'
|
nginx_pkgng_package: 'nginx-devel'
|
||||||
nginx_user: 'www'
|
nginx_user: 'www'
|
||||||
nginx_php_sockets:
|
nginx_php70: false
|
||||||
|
nginx_php56_sockets:
|
||||||
- host: '127.0.0.1'
|
- host: '127.0.0.1'
|
||||||
port: 9000
|
port: 9000
|
||||||
|
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
localhost
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# Thanks to https://servercheck.in/blog/testing-ansible-roles-travis-ci-github
|
|
||||||
|
|
||||||
DIR=$( dirname $0 )
|
|
||||||
INVENTORY_FILE="$DIR/inventory"
|
|
||||||
PLAYBOOK="$DIR/test.yml"
|
|
||||||
|
|
||||||
set -ev
|
|
||||||
|
|
||||||
# Check syntax
|
|
||||||
ansible-playbook -i $INVENTORY_FILE -c local --syntax-check -vv $PLAYBOOK
|
|
||||||
|
|
||||||
# Check role
|
|
||||||
ansible-playbook -i $INVENTORY_FILE -c local --sudo -vv $PLAYBOOK
|
|
||||||
|
|
||||||
# Check indempotence
|
|
||||||
ansible-playbook -i $INVENTORY_FILE -c local --sudo -vv $PLAYBOOK \
|
|
||||||
| grep -q 'changed=0.*failed=0' \
|
|
||||||
&& (echo 'Idempotence test: pass' && exit 0) \
|
|
||||||
|| (echo 'Idempotence test: fail' && exit 1)
|
|
||||||
100
tests/test.yml
100
tests/test.yml
@@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
- hosts: all
|
- hosts: all
|
||||||
pre_tasks:
|
pre_tasks:
|
||||||
|
- debug: var=dotdeb
|
||||||
|
- debug: var=nginx_php56
|
||||||
|
- debug: var=nginx_php70
|
||||||
|
- debug: var=nginx_backports
|
||||||
- name: INCLUDE | Pre_tasks related to OS version
|
- name: INCLUDE | Pre_tasks related to OS version
|
||||||
include: "includes/pre_{{ ansible_distribution }}.yml"
|
include: "includes/pre_{{ ansible_distribution }}.yml"
|
||||||
- name: FILE | Create an internal SSL dir
|
- name: FILE | Create an internal SSL dir
|
||||||
@@ -15,8 +19,8 @@
|
|||||||
int_ansible_ssl_dir: '/etc/ansible-ssl'
|
int_ansible_ssl_dir: '/etc/ansible-ssl'
|
||||||
# Role vars
|
# Role vars
|
||||||
nginx_worker_processes: 1 # Ansible+FreeBSD can't detect CPU number
|
nginx_worker_processes: 1 # Ansible+FreeBSD can't detect CPU number
|
||||||
nginx_backports: true
|
nginx_apt_package: 'nginx-extras'
|
||||||
nginx_php: true
|
nginx_dyn_modules: ['http_geoip']
|
||||||
nginx_upstreams:
|
nginx_upstreams:
|
||||||
- name: 'test'
|
- name: 'test'
|
||||||
servers:
|
servers:
|
||||||
@@ -24,6 +28,13 @@
|
|||||||
max_conns: 150
|
max_conns: 150
|
||||||
weight: 10
|
weight: 10
|
||||||
down: false
|
down: false
|
||||||
|
- name: 'test-absent'
|
||||||
|
servers:
|
||||||
|
- path: '127.0.0.1:80'
|
||||||
|
max_conns: 150
|
||||||
|
weight: 10
|
||||||
|
down: false
|
||||||
|
state: 'absent'
|
||||||
nginx_htpasswd:
|
nginx_htpasswd:
|
||||||
- name: 'hello'
|
- name: 'hello'
|
||||||
description: 'Please login!'
|
description: 'Please login!'
|
||||||
@@ -97,7 +108,14 @@
|
|||||||
-----END CERTIFICATE-----
|
-----END CERTIFICATE-----
|
||||||
nginx_custom_http:
|
nginx_custom_http:
|
||||||
- 'add_header X-ansible 1;'
|
- 'add_header X-ansible 1;'
|
||||||
nginx_default_vhost: 'test.local'
|
- 'geoip_country /usr/share/GeoIP/GeoIP.dat;'
|
||||||
|
- 'map $geoip_country_code $allowed_country {'
|
||||||
|
- ' default yes;'
|
||||||
|
- ' MA no;'
|
||||||
|
- ' DZ no;'
|
||||||
|
- ' TN no;'
|
||||||
|
- '}'
|
||||||
|
nginx_default_vhost: 'first-test'
|
||||||
nginx_default_vhost_ssl: 'test-ssl-predeployed.local'
|
nginx_default_vhost_ssl: 'test-ssl-predeployed.local'
|
||||||
nginx_vhosts:
|
nginx_vhosts:
|
||||||
- name:
|
- name:
|
||||||
@@ -111,7 +129,7 @@
|
|||||||
'X-Frame-Options': 'deny always'
|
'X-Frame-Options': 'deny always'
|
||||||
'X-ansible-default': '1'
|
'X-ansible-default': '1'
|
||||||
manage_local_content: false
|
manage_local_content: false
|
||||||
use_error_log: false
|
use_error_log: true
|
||||||
more:
|
more:
|
||||||
- 'autoindex off;'
|
- 'autoindex off;'
|
||||||
location:
|
location:
|
||||||
@@ -129,6 +147,7 @@
|
|||||||
location:
|
location:
|
||||||
'/hello':
|
'/hello':
|
||||||
- htpasswd: 'hello'
|
- htpasswd: 'hello'
|
||||||
|
use_error_log: true
|
||||||
- name: 'test-htpasswd-all.local'
|
- name: 'test-htpasswd-all.local'
|
||||||
template: '_base'
|
template: '_base'
|
||||||
htpasswd: 'hello'
|
htpasswd: 'hello'
|
||||||
@@ -137,7 +156,19 @@
|
|||||||
location:
|
location:
|
||||||
'/':
|
'/':
|
||||||
- 'alias /var/tmp;'
|
- 'alias /var/tmp;'
|
||||||
|
'/a':
|
||||||
|
- 'alias /var/tmp;'
|
||||||
|
'/b':
|
||||||
|
- 'alias /var/tmp;'
|
||||||
|
'/c':
|
||||||
|
- 'alias /var/tmp;'
|
||||||
|
location_order:
|
||||||
|
- '/'
|
||||||
|
- '/a'
|
||||||
|
- '/b'
|
||||||
|
- '/c'
|
||||||
- name: 'test-php.local'
|
- name: 'test-php.local'
|
||||||
|
php_version: "{{ '7.0' if nginx_php70 else '5.6' }}"
|
||||||
upstream_params:
|
upstream_params:
|
||||||
- 'fastcgi_param FOO bar;'
|
- 'fastcgi_param FOO bar;'
|
||||||
redirect_from:
|
redirect_from:
|
||||||
@@ -155,7 +186,7 @@
|
|||||||
headers:
|
headers:
|
||||||
'X-proxyfied': '1'
|
'X-proxyfied': '1'
|
||||||
- name: 'deleted.local'
|
- name: 'deleted.local'
|
||||||
delete: true
|
state: 'absent'
|
||||||
- name: 'redirect-to.local'
|
- name: 'redirect-to.local'
|
||||||
redirect_to: 'http://test.local'
|
redirect_to: 'http://test.local'
|
||||||
- name: 'backuppc.local'
|
- name: 'backuppc.local'
|
||||||
@@ -167,7 +198,6 @@
|
|||||||
- name: 'test-ssl.local'
|
- name: 'test-ssl.local'
|
||||||
proto: ['http', 'https']
|
proto: ['http', 'https']
|
||||||
template: '_base'
|
template: '_base'
|
||||||
ssl_name: 'test-ssl.local'
|
|
||||||
- name: 'test-ssl-predeployed.local'
|
- name: 'test-ssl-predeployed.local'
|
||||||
proto: ['http', 'https']
|
proto: ['http', 'https']
|
||||||
template: '_base'
|
template: '_base'
|
||||||
@@ -180,7 +210,15 @@
|
|||||||
template: '_base'
|
template: '_base'
|
||||||
ssl_name: 'test-ssl.local'
|
ssl_name: 'test-ssl.local'
|
||||||
redirect_https: true
|
redirect_https: true
|
||||||
nginx_dh_length: 1024
|
- name: 'test-ssl-proxy-protocol.local'
|
||||||
|
proto: ['http', 'https']
|
||||||
|
listen: [80, 20080]
|
||||||
|
listen_ssl: [443, 20443]
|
||||||
|
http_proxy_protocol_port: [20080]
|
||||||
|
https_proxy_protocol_port: [20443]
|
||||||
|
template: '_base'
|
||||||
|
ssl_name: 'test-ssl.local'
|
||||||
|
nginx_dh_length: 2048
|
||||||
roles:
|
roles:
|
||||||
- ../../
|
- ../../
|
||||||
post_tasks:
|
post_tasks:
|
||||||
@@ -197,18 +235,24 @@
|
|||||||
with_items: ['test-php.local', 'test-php-index.local']
|
with_items: ['test-php.local', 'test-php-index.local']
|
||||||
- name: -- Add HTML file --
|
- name: -- Add HTML file --
|
||||||
copy: dest="{{ item }}/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', '{{ nginx_root }}/test-htpasswd-all.local/public', '{{ nginx_root }}/test-ssl.local/public', '{{ nginx_root }}/test-ssl-predeployed.local/public']
|
with_items: ['{{ nginx_root }}/first-test/public', '/var/tmp', '{{ nginx_root }}/test-htpasswd-all.local/public', '{{ nginx_root }}/test-ssl.local/public', '{{ nginx_root }}/test-ssl-predeployed.local/public', '{{ nginx_root }}/test-ssl-proxy-protocol.local/public']
|
||||||
- name: -- Create directory --
|
- name: -- Create directory --
|
||||||
file: path={{ nginx_root }}/test-htpasswd.local/public/hello state=directory
|
file: path={{ nginx_root }}/test-htpasswd.local/public/hello state=directory
|
||||||
- name: -- Add HTML file hello --
|
- name: -- Add HTML file hello --
|
||||||
copy: dest="{{ nginx_root }}/test-htpasswd.local/public/hello/index.html" content="hello\n"
|
copy: dest="{{ nginx_root }}/test-htpasswd.local/public/hello/index.html" content="hello\n"
|
||||||
# --------------------------------
|
# --------------------------------
|
||||||
|
# Test custom facts
|
||||||
|
# --------------------------------
|
||||||
|
- name: -- CHECK FACTS --
|
||||||
|
assert:
|
||||||
|
that: "'{{ ansible_local.nginx.fact_nginx_vhosts[0].name[0] }}' == 'test.local'"
|
||||||
|
# --------------------------------
|
||||||
# Simple vhosts tests
|
# Simple vhosts tests
|
||||||
# --------------------------------
|
# --------------------------------
|
||||||
- name: -- VERIFY VHOSTS --
|
- name: -- VERIFY VHOSTS --
|
||||||
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 %}/"
|
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 }}"
|
with_items: "{{ nginx_vhosts }}"
|
||||||
when: item.delete is undefined or not item.delete
|
when: item.state is undefined or item.state != "absent"
|
||||||
changed_when: false
|
changed_when: false
|
||||||
- name: -- VERIFY FORBIDDEN --
|
- name: -- VERIFY FORBIDDEN --
|
||||||
command: "curl -H 'Host: test-php-index.local' http://127.0.0.1/phpinfo.php"
|
command: "curl -H 'Host: test-php-index.local' http://127.0.0.1/phpinfo.php"
|
||||||
@@ -218,7 +262,7 @@
|
|||||||
- name: -- VERIFY REDIRECT VHOSTS --
|
- name: -- VERIFY REDIRECT VHOSTS --
|
||||||
command: "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 }}"
|
with_items: "{{ nginx_vhosts }}"
|
||||||
when: item.redirect_from is defined and (item.delete is undefined or not item.delete)
|
when: item.redirect_from is defined and (item.state is undefined or item.state != "absent")
|
||||||
changed_when: false
|
changed_when: false
|
||||||
register: r
|
register: r
|
||||||
failed_when: r.stdout.find('301 Moved Permanently') == -1
|
failed_when: r.stdout.find('301 Moved Permanently') == -1
|
||||||
@@ -226,12 +270,21 @@
|
|||||||
# --------------------------------
|
# --------------------------------
|
||||||
# PHP
|
# PHP
|
||||||
# --------------------------------
|
# --------------------------------
|
||||||
- name: -- VERIFY PHP VHOSTS --
|
- name: -- VERIFY PHP5 VHOSTS (implicit default) --
|
||||||
command: "curl -H 'Host: {{ item }}' http://127.0.0.1/"
|
command: "curl -H 'Host: {{ item }}' http://127.0.0.1/"
|
||||||
register: p
|
register: p
|
||||||
changed_when: false
|
changed_when: false
|
||||||
failed_when: p.stdout.find('PHP Version') == -1
|
failed_when: p.stdout.find('PHP Version 5') == -1
|
||||||
with_items: ['test-php.local', 'test-php-index.local']
|
with_items: ['test-php-index.local']
|
||||||
|
when: nginx_php56
|
||||||
|
|
||||||
|
- name: -- VERIFY PHP7 VHOSTS --
|
||||||
|
command: "curl -H 'Host: {{ item }}' http://127.0.0.1/"
|
||||||
|
register: p
|
||||||
|
changed_when: false
|
||||||
|
failed_when: p.stdout.find('PHP Version 7') == -1
|
||||||
|
with_items: ['test-php.local']
|
||||||
|
when: nginx_php70
|
||||||
|
|
||||||
# --------------------------------
|
# --------------------------------
|
||||||
# Basic Auth
|
# Basic Auth
|
||||||
@@ -286,6 +339,27 @@
|
|||||||
register: nagios_cgi
|
register: nagios_cgi
|
||||||
failed_when: nagios_cgi.stdout.find('Nagios Event Summary') == -1
|
failed_when: nagios_cgi.stdout.find('Nagios Event Summary') == -1
|
||||||
|
|
||||||
|
# --------------------------------
|
||||||
|
# Owncloud
|
||||||
|
# --------------------------------
|
||||||
|
# - block:
|
||||||
|
# - name: -- VERIFY OWNCLOUD --
|
||||||
|
# command: "curl -H 'Host: owncloud.local' http://127.0.0.1/"
|
||||||
|
# changed_when: false
|
||||||
|
# register: ownsimple
|
||||||
|
# failed_when: ownsimple.stdout.find('ownCloud') == -1
|
||||||
|
# - name: -- VERIFY OWNCLOUD JS (FROM PHP)--
|
||||||
|
# command: "curl -H 'Host: owncloud.local' http://127.0.0.1/index.php/core/js/oc.js"
|
||||||
|
# changed_when: false
|
||||||
|
# register: ownjsphp
|
||||||
|
# failed_when: ownjsphp.stdout.find('var oc_debug=false') == -1
|
||||||
|
# - name: -- VERIFY OWNCLOUD JS --
|
||||||
|
# command: "curl -H 'Host: owncloud.local' http://127.0.0.1/core/js/js.js"
|
||||||
|
# changed_when: false
|
||||||
|
# register: ownjs
|
||||||
|
# failed_when: ownjs.stdout.find('var oc_debug') == -1
|
||||||
|
# when: ansible_distribution != 'FreeBSD'
|
||||||
|
|
||||||
# --------------------------------
|
# --------------------------------
|
||||||
# SSL
|
# SSL
|
||||||
# --------------------------------
|
# --------------------------------
|
||||||
|
|||||||
25
tests/travis.sh
Normal file
25
tests/travis.sh
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Thanks to https://servercheck.in/blog/testing-ansible-roles-travis-ci-github
|
||||||
|
|
||||||
|
DIR=$( dirname $0 )
|
||||||
|
PLAYBOOK="$DIR/test.yml"
|
||||||
|
|
||||||
|
|
||||||
|
set -ev
|
||||||
|
|
||||||
|
ANSIBLE_VARS="{ nginx_php56: $NGINX_PHP56, nginx_php70: $NGINX_PHP70, nginx_backports: $NGINX_BACKPORTS, dotdeb: $DOTDEB }"
|
||||||
|
|
||||||
|
echo $ANSIBLE_VARS
|
||||||
|
|
||||||
|
# Check syntax
|
||||||
|
ansible-playbook -i localhost, -c local --syntax-check -vv $PLAYBOOK
|
||||||
|
|
||||||
|
# Check role
|
||||||
|
ansible-playbook -i localhost, -c local -e "$ANSIBLE_VARS" --sudo -vv $PLAYBOOK
|
||||||
|
|
||||||
|
# Check indempotence
|
||||||
|
ansible-playbook -i localhost, -c local -e "$ANSIBLE_VARS" --sudo -vv $PLAYBOOK \
|
||||||
|
| grep -q 'changed=0.*failed=0' \
|
||||||
|
&& (echo 'Idempotence test: pass' && exit 0) \
|
||||||
|
|| (echo 'Idempotence test: fail' && exit 1)
|
||||||
@@ -23,11 +23,21 @@ nginx_upstream_server_params:
|
|||||||
# min_version: '1.5.12'
|
# min_version: '1.5.12'
|
||||||
|
|
||||||
nginx_dirs:
|
nginx_dirs:
|
||||||
- "{{ nginx_htpasswd_dir }}"
|
- dir: "{{ nginx_htpasswd_dir }}"
|
||||||
- "{{ nginx_ssl_dir }}"
|
mode: "0750"
|
||||||
- "{{ nginx_helper_dir }}"
|
owner: "{{ nginx_user }}"
|
||||||
|
- dir: "{{ nginx_ssl_dir }}"
|
||||||
|
mode: "0750"
|
||||||
|
owner: "root"
|
||||||
|
- dir: "{{ nginx_helper_dir }}"
|
||||||
|
mode: "0755"
|
||||||
|
owner: "root"
|
||||||
|
|
||||||
nginx_templates_no_dir:
|
nginx_templates_no_dir:
|
||||||
- '_proxy'
|
|
||||||
- '_nagios3'
|
|
||||||
- '_backuppc'
|
- '_backuppc'
|
||||||
|
- '_nagios3'
|
||||||
|
- '_owncloud'
|
||||||
|
- '_proxy'
|
||||||
|
|
||||||
|
nginx_upstream_php56: 'php56'
|
||||||
|
nginx_upstream_php70: 'php70'
|
||||||
|
|||||||
Reference in New Issue
Block a user