66 Commits
1.1.0 ... 1.3.0

Author SHA1 Message Date
Emilien Mantel
3ab8e0391c Disable tests for owncloud (fix later) 2016-08-25 18:19:07 +02:00
Emilien Mantel
aac33b7376 better vhost for owncloud 2016-08-11 13:03:56 +02:00
Emilien Mantel
88c6c5a043 Manages PHP minor versions 2016-08-11 11:30:26 +02:00
Emilien Mantel
a9ad41b40f Fix more block for owncloud 2016-08-11 11:09:43 +02:00
Emilien Mantel
d26b2b9a49 Fix owncloud root 2016-08-11 10:59:44 +02:00
Emilien Mantel
b17acac4c4 Tests packages on Debian 2016-08-11 10:48:12 +02:00
Emilien Mantel
c160640c7f Force latest version of openssl when uses nginx from backports 2016-08-11 10:36:50 +02:00
Emilien Mantel
887219f86c Force install OpenSSL from backports when nginx uses backports 2016-08-11 10:25:45 +02:00
Emilien Mantel
76c02abf47 Fix owncloud js (from php) and add tests 2016-08-11 09:38:09 +02:00
Emilien Mantel
26c93c9315 Add owncloud and prevent nginx from dotdeb 2016-08-10 21:29:03 +02:00
Emilien Mantel
8fb3829860 Drop Wheezy support in IC 2016-08-09 16:12:54 +02:00
Emilien Mantel
e4b5bb2a32 Support many php versions (php7) + drop wheezy support 2016-08-09 16:02:09 +02:00
Emilien Mantel
af3930a58a New feature: upstream state (remove upstream if needed) 2016-05-11 17:21:52 +02:00
Emilien Mantel
4dcb5f44c6 Don't need any inventory file for tests 2016-03-23 17:27:59 +01:00
Emilien Mantel
1204dbacd1 [FreeBSD] Enable nginx service 2016-03-15 23:12:17 +01:00
Emilien Mantel
3087154335 [FreeBSD] restart nginx on vhost config changed 2016-03-15 23:00:55 +01:00
Emilien Mantel
72edbe8656 [FreeBSD] Force create log dir 2016-03-15 22:49:19 +01:00
E Mantel
66b2ac238c README: Change URL in galaxy 2016-03-15 19:48:00 +01:00
Emilien Mantel
d49e41652c Update cipher list (from https://cipherli.st/) 2016-03-15 17:59:48 +01:00
Emilien Mantel
9b19231d8b use headers instead of more 2016-03-15 17:15:46 +01:00
Emilien Mantel
80d1d82acc Fix handler (didn't reload service after nginx -t) 2016-03-15 17:15:11 +01:00
Emilien Mantel
5445d66172 Add a wrapper: test configuration before reloading (better debugging) 2016-03-15 15:57:46 +01:00
Emilien Mantel
9a5afd09fa Force X-Frame-Options SAMEORIGIN for Nagios (closes #17) 2016-03-15 15:46:49 +01:00
Emilien Mantel
96e406c791 always directive managed for add_header option 2016-03-15 15:30:22 +01:00
Emilien Mantel
02994af5ee Default headers with always directive 2016-03-15 15:01:58 +01:00
Emilien Mantel
ee79ec9845 SSL helper can be disabled 2016-03-15 12:16:57 +01:00
Emilien Mantel
2ba906be2e Add custom headers in vhost (moved from ssl helpers) 2016-03-15 10:51:14 +01:00
Emilien Mantel
d223f8b144 Add a check for HTTPS redirect 2016-03-15 09:22:01 +01:00
Emilien Mantel
8f837de390 Avoid double / in redirect_https 2016-03-15 09:08:52 +01:00
Emilien Mantel
aa4bc8d6a7 Move to new galaxy version 2016-03-14 19:39:11 +01:00
Emilien Mantel
2fcf7fa701 Delete useless files 2016-03-14 19:37:25 +01:00
Emilien Mantel
91686fc266 doc minor fix 2016-03-14 19:27:51 +01:00
Emilien Mantel
5e493c15ac Fix deprecation warning 2016-03-14 19:21:47 +01:00
Emilien Mantel
97aeda5678 New feature: redirect_https (HTTP -> HTTPS) 2016-03-14 19:20:08 +01:00
Emilien Mantel
3666b29184 nghttp2 only on Debian Jessie+ 2016-03-09 15:03:41 +01:00
Emilien Mantel
9b5f136510 Fix trailing whitespaces 2016-03-09 11:20:19 +01:00
Emilien Mantel
7cc44bc009 Fix regression (merge?): filename for vhosts 2016-03-09 11:15:37 +01:00
Emilien Mantel
078c3420e1 Fix Vagrantfile (debian is not freebsd)... uh? :) 2016-03-09 10:28:06 +01:00
Emilien Mantel
2cfda9a930 Fix check HTTP2 on FreeBSD (multi-OS code) 2016-03-08 19:37:39 +01:00
E Mantel
29a40fc0a8 Merge pull request #14 from HanXHX/freebsd
Freebsd support
2016-03-08 18:59:38 +01:00
Emilien Mantel
33f34a0550 Manage FreeBSD nginx package name 2016-03-07 12:08:34 +01:00
Emilien Mantel
8fc6f7117e Doc fixes 2016-03-07 12:05:58 +01:00
Emilien Mantel
972555ce22 Minor fixes 2016-03-07 11:59:26 +01:00
Emilien Mantel
2f0672359d I support now FreeBSD! 2016-03-05 18:43:49 +01:00
Emilien Mantel
cdc152afbe Nagios OK on FreeBSD 2016-03-05 18:34:04 +01:00
Emilien Mantel
729b621ccb Fix check htpasswd in location (replace echo test) 2016-03-05 17:31:21 +01:00
Emilien Mantel
c13cb0d770 PHP works on FreeBSD 2016-03-05 17:26:05 +01:00
Emilien Mantel
8edd69547d [WIP] split pre/post tasks related to OS version 2016-03-05 15:46:54 +01:00
Emilien Mantel
791832f6d1 Config seems ok 2016-03-05 15:36:25 +01:00
Emilien Mantel
e00313bb36 [WIP] FreeBSD install ok 2016-03-05 15:07:39 +01:00
Emilien Mantel
44a5c31b12 Typofix 2016-03-05 12:12:09 +01:00
Emilien Mantel
232e63dffe Add travis webhook to galaxy 2016-03-05 12:06:08 +01:00
Emilien Mantel
fe68e17663 Logging must be set to false to be disabled 2016-03-05 12:00:07 +01:00
Emilien Mantel
ac61b3df0a Add new galaxy tags 2016-03-05 11:40:43 +01:00
Emilien Mantel
1071881ac2 Merge branch 'master' of https://github.com/HanXHX/ansible-nginx
Conflicts:
	tasks/vhost.yml
2016-03-05 11:39:29 +01:00
Emilien Mantel
e139ab3e35 Fix deprecation warnings 2016-03-05 11:37:37 +01:00
Emilien Mantel
1f82e7adfe Add HTTP2 check 2016-03-05 11:30:48 +01:00
Emilien Mantel
e43a958b03 Gitignore *.retry 2016-03-05 11:06:34 +01:00
Emilien Mantel
47c24a2eb3 Fix HTTP2 syntax error 2016-03-05 10:59:20 +01:00
Emilien Mantel
82c44be932 Use official debian box and DHCP 2016-03-05 10:46:46 +01:00
Emilien Mantel
781008dfff Each vhost can have his own filename 2016-03-04 16:38:40 +01:00
Emilien Mantel
26a50945c5 Split apt update cache (fix install when cache is outdated) 2016-02-09 18:36:48 +01:00
Emilien Mantel
4dc28d9471 Delete useless tasks 2016-02-09 17:17:44 +01:00
Emilien Mantel
3231e58bc0 Test stub status on default http vhost 2016-02-09 16:57:13 +01:00
Emilien Mantel
d4f9b6f710 Fix default var nginx_custom_http 2016-01-26 11:19:51 +01:00
Emilien Mantel
d049be0d81 Remove duplicate link 2016-01-25 17:02:17 +01:00
46 changed files with 711 additions and 195 deletions

1
.gitignore vendored
View File

@@ -1,2 +1,3 @@
.vagrant* .vagrant*
*.swp *.swp
*.retry

View File

@@ -1,5 +1,4 @@
env: env:
- PLATFORM=debian-wheezy
- PLATFORM=debian-jessie - PLATFORM=debian-jessie
sudo: required sudo: required
@@ -11,3 +10,6 @@ services:
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 --name $PLATFORM test-$PLATFORM
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/

View File

@@ -1,9 +1,9 @@
Nginx for Debian Ansible role Nginx for Debian/FreeBSD Ansible role
============================= =====================================
[![Ansible Galaxy](http://img.shields.io/badge/ansible--galaxy-HanXHX.nginx-blue.svg)](https://galaxy.ansible.com/list#/roles/4399) [![Build Status](https://travis-ci.org/HanXHX/ansible-nginx.svg?branch=master)](https://travis-ci.org/HanXHX/ansible-nginx) [![Ansible Galaxy](http://img.shields.io/badge/ansible--galaxy-HanXHX.nginx-blue.svg)](https://galaxy.ansible.com/HanXHX/nginx/) [![Build Status](https://travis-ci.org/HanXHX/ansible-nginx.svg?branch=master)](https://travis-ci.org/HanXHX/ansible-nginx)
Install and configure Nginx on Debian. Install and configure Nginx on Debian/FreeBSD.
Features: Features:
@@ -24,9 +24,15 @@ Role Variables
### Packaging ### Packaging
Debian:
- `nginx_apt_package`: APT nginx package (try: apt-cache search ^nginx) - `nginx_apt_package`: APT nginx package (try: apt-cache search ^nginx)
- `nginx_backports`: Install nginx from backport repository (bool) - `nginx_backports`: Install nginx from backport repository (bool)
FreeBSD:
- `nginx_pkgng_package`: PKGNG nginx package (should be "nginx" or "nginx-devel")
### Shared ### Shared
- `nginx_root`: root directory where you want to have your files - `nginx_root`: root directory where you want to have your files
@@ -53,12 +59,19 @@ Fine configuration
[Upstream Configuration](doc/upstream.md) [Upstream Configuration](doc/upstream.md)
[Vhost configuration](doc/vhost.md)
[SSL/TLS Configuration](doc/ssl.md) [SSL/TLS Configuration](doc/ssl.md)
[Basic Auth](doc/auth.md) [Basic Auth](doc/auth.md)
[FreeBSD](doc/freebsd.md)
Note
----
- Active support for Debian.
- FreeBSD support is experimental (no Travis). I only test (for the moment) 10.2 (but it can work on other versions).
- I don't manage BackupPC for FreeBSD (PR welcome).
Dependencies Dependencies
------------ ------------

37
Vagrantfile vendored
View File

@@ -5,10 +5,13 @@
Vagrant.configure("2") do |config| Vagrant.configure("2") do |config|
vms = [ vms_debian = [
[ "debian-wheezy", "deb/wheezy-amd64" , "192.168.33.27" ], [ "debian-jessie", "debian/jessie64" ],
[ "debian-jessie", "deb/jessie-amd64", "192.168.33.28" ], [ "debian-stretch", "sharlak/debian_stretch_64" ]
[ "debian-stretch", "sharlak/debian_stretch_64", "192.168.33.29" ] ]
vms_freebsd = [
[ "freebsd-10.2", "freebsd/FreeBSD-10.2-STABLE" ]
] ]
config.vm.provider "virtualbox" do |v| config.vm.provider "virtualbox" do |v|
@@ -16,11 +19,10 @@ Vagrant.configure("2") do |config|
v.memory = 256 v.memory = 256
end end
vms.each do |vm| vms_debian.each do |vm|
config.vm.define vm[0] do |m| config.vm.define vm[0] do |m|
m.vm.box = vm[1] m.vm.box = vm[1]
m.vm.network "private_network", ip: vm[2] 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.groups = { "test" => [ vm[0] ] }
@@ -29,4 +31,25 @@ Vagrant.configure("2") do |config|
end end
end end
end end
# See: https://forums.freebsd.org/threads/52717/
vms_freebsd.each do |vm|
config.vm.define vm[0] do |m|
m.vm.box = vm[1]
m.vm.network "private_network", type: "dhcp"
m.vm.guest = :freebsd
m.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: true
m.ssh.shell = "sh"
m.vm.base_mac = "080027D14C66"
m.vm.provision "shell", inline: "pkg install -y python bash"
m.vm.provision "ansible" do |ansible|
ansible.playbook = "tests/test.yml"
ansible.groups = { "test" => [ vm[0] ] }
ansible.verbose = 'vv'
ansible.sudo = true
ansible.extra_vars = {
ansible_python_interpreter: '/usr/local/bin/python'
}
end
end
end
end end

View File

@@ -1,14 +1,16 @@
--- ---
# Debian
nginx_apt_package: nginx-full nginx_apt_package: nginx-full
nginx_backports: false nginx_backports: false
# FreeBSD
nginx_pkgng_package: nginx
# #
# Nginx shared variables # Nginx shared variables
# #
nginx_root: "/srv/www" nginx_root: "/srv/www"
nginx_log_dir: '/var/log/nginx' nginx_log_dir: '/var/log/nginx'
nginx_pid: '/run/nginx.pid'
nginx_resolver_hosts: ['8.8.8.8', '8.8.4.4'] nginx_resolver_hosts: ['8.8.8.8', '8.8.4.4']
nginx_resolver_valid: '300s' nginx_resolver_valid: '300s'
nginx_resolver_timeout: '5s' nginx_resolver_timeout: '5s'
@@ -20,18 +22,21 @@ nginx_default_vhost_ssl: null
# #
# Nginx directories # Nginx directories
# #
nginx_htpasswd_dir: '/etc/nginx/htpasswd' nginx_htpasswd_dir: '{{ nginx_etc_dir }}/htpasswd'
nginx_ssl_dir: '/etc/nginx/ssl' nginx_ssl_dir: '{{ nginx_etc_dir }}/ssl'
nginx_helper_dir: '/etc/nginx/helper' nginx_helper_dir: '{{ nginx_etc_dir}}/helper'
# #
# Load upstream # Load upstream
# #
# 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: []
# #
@@ -45,7 +50,6 @@ nginx_worker_processes: '{{ ansible_processor_vcpus }}'
# #
nginx_events_worker_connections: '512' nginx_events_worker_connections: '512'
nginx_events_multi_accept: 'on' nginx_events_multi_accept: 'on'
nginx_events_use: 'epoll'
# #
# Nginx HTTP # Nginx HTTP
@@ -81,9 +85,9 @@ nginx_http_gzip_vary: 'on'
nginx_http_gzip_disable: '"msie6"' nginx_http_gzip_disable: '"msie6"'
# #
# nginx_http_custom # Custom global configuration
# #
nginx_http_custom: [] nginx_custom_http: []
# #
# Vhosts # Vhosts
@@ -106,3 +110,10 @@ nginx_ssl_pairs: []
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'

View File

@@ -10,15 +10,15 @@ Each htpasswd has few keys:
- `name`: (M) used to create file and as pointee - `name`: (M) used to create file and as pointee
- `description`: (M) Used for the message box :) - `description`: (M) Used for the message box :)
- `users`: each users is composed with 3 keys: `name` (M), `password` (M) and `state` present/absent (default: present) - `users`: each users is composed with 3 keys: `name` (M), `password` (M) and `state` (O) present/absent (default: present)
- `state`: (O) present or absent. Default: present - `state`: (O) present or absent. Default: present
`nginx_htpasswd` should be placed in a vaut file. `nginx_htpasswd` should be placed in a vault file.
Example Example
------- -------
``` ```yaml
nginx_vhosts: nginx_vhosts:
# htpasswd on all vhost # htpasswd on all vhost
- name: test.local - name: test.local

4
doc/freebsd.md Normal file
View File

@@ -0,0 +1,4 @@
Freebsd
=======
Due to Ansible + FreeBSD limitations (`ansible_processor_vcpus`), You must explicitely set `nginx_worker_processes`.

View File

@@ -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.

View File

@@ -27,7 +27,6 @@ OR
- `dest_cert`: remote path where certificate is located - `dest_cert`: remote path where certificate is located
- `dest_key`: remote path where key is located - `dest_key`: remote path where key is located
Note: `name` is used to deploy key/cert. With defaults values dans `name` = "foo", key is -> /etc/nginx/ssl/foo/foo.key Note: `name` is used to deploy key/cert. With defaults values dans `name` = "foo", key is -> /etc/nginx/ssl/foo/foo.key
Tips Tips
@@ -35,9 +34,6 @@ 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`!
If you set all, you can deploy your key everywhere with wanted data!
Diffie-Hellman Diffie-Hellman
-------------- --------------
@@ -46,7 +42,7 @@ If you do not specify any dh param, this role auto generates it.
Example Example
------- -------
``` ```yaml
nginx_vhosts; nginx_vhosts;
- name: 'test-ssl.local' - name: 'test-ssl.local'
proto: ['http', 'https'] proto: ['http', 'https']

View File

@@ -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
------------- -------------
@@ -25,5 +26,18 @@ All this params are optional. You should see [Nginx upstream doc](http://nginx.o
- `backup` - `backup`
- `down` - `down`
- `route` - `route`
- `slow`start` - `slow_start`
Example
-------
```yaml
nginx_upstreams:
- name: 'proxy_apache'
servers:
- path: '127.0.0.1:80'
max_conns: 150
weight: 10
down: false
state: 'present'
```

View File

@@ -10,11 +10,14 @@ 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).
- `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
- `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).
- `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']```.
- `location`: (O) Add new custom locations (it does not overwrite!) - `location`: (O) Add new custom locations (it does not overwrite!)
- `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)
@@ -23,6 +26,8 @@ Common
- `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. Mandatory when `proto` contains "https"
- `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)
(O): Optional (O): Optional
(M): Mandatory (M): Mandatory
@@ -36,6 +41,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

View File

@@ -1 +0,0 @@
<h1>HTML works</h1>

View File

@@ -1,3 +0,0 @@
<?php
echo "<h1>PHP works!</h1>";

View File

@@ -1,4 +1,13 @@
--- ---
# Reload wrapper
- name: reload nginx - name: reload nginx
action: service name=nginx state=reloaded enabled=yes command: nginx -t
notify: real-reload nginx
- name: real-reload nginx
service: name=nginx state=reloaded
- name: restart nginx freebsd
service: name=nginx state=restarted
when: ansible_distribution == "FreeBSD"

View File

@@ -8,9 +8,19 @@ galaxy_info:
platforms: platforms:
- name: Debian - name: Debian
versions: versions:
- wheezy
- jessie - jessie
categories: - name: FreeBSD
versions:
- 10.2
galaxy_tags:
- web - web
- proxy
- http
- http2
- https
- ssl
- tls
- nginx
- cdn
dependencies: [] dependencies: []

View File

@@ -3,7 +3,7 @@
- name: TEMPLATE | Deploy nginx.conf - name: TEMPLATE | Deploy nginx.conf
template: > template: >
src=etc/nginx/nginx.conf.j2 src=etc/nginx/nginx.conf.j2
dest=/etc/nginx/nginx.conf dest="{{ nginx_etc_dir }}/nginx.conf"
notify: reload nginx notify: reload nginx
- name: TEMPLATE | Deploy all helpers - name: TEMPLATE | Deploy all helpers
@@ -16,6 +16,6 @@
- name: TEMPLATE | Deploy custom http configuration - name: TEMPLATE | Deploy custom http configuration
template: > template: >
src=etc/nginx/conf.d/custom.conf.j2 src=etc/nginx/conf.d/custom.conf.j2
dest=/etc/nginx/conf.d/custom.conf dest="{{ nginx_etc_dir }}/conf.d/custom.conf"
notify: reload nginx notify: reload nginx

View File

@@ -4,7 +4,7 @@
file: > file: >
path={{ nginx_htpasswd_dir }}/{{ item.name }} path={{ nginx_htpasswd_dir }}/{{ item.name }}
state=absent state=absent
with_items: nginx_htpasswd with_items: "{{ nginx_htpasswd }}"
when: item.state is defined and item.state == 'absent' when: item.state is defined and item.state == 'absent'
- name: HTPASSWD | Manage files - name: HTPASSWD | Manage files
@@ -14,6 +14,6 @@
state={{ item.1.state | default('present') }} state={{ item.1.state | default('present') }}
path={{ nginx_htpasswd_dir }}/{{ item.0.name }} path={{ nginx_htpasswd_dir }}/{{ item.0.name }}
with_subelements: with_subelements:
- 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'

View File

@@ -1,11 +1,21 @@
--- ---
- name: APT | Update cache
apt: >
update_cache=yes
cache_valid_time=3600
- 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: >
pkg={{ nginx_apt_package }} pkg={{ nginx_apt_package }}
state=present state=present
update_cache=yes
cache_valid_time=3600
default_release={{ ansible_distribution_release + '-backports' if nginx_backports else ansible_distribution_release }} default_release={{ ansible_distribution_release + '-backports' if nginx_backports else ansible_distribution_release }}
- name: APT | Install python-passlib - name: APT | Install python-passlib

46
tasks/install_FreeBSD.yml Normal file
View File

@@ -0,0 +1,46 @@
---
- name: PKGNG | Install nginx and related tools
pkgng: name={{ item }} state=present
with_items:
- "{{ nginx_pkgng_package }}"
- py27-passlib
- curl
- name: FILE | Create configuration dir (like Debian)
file: path="{{ nginx_etc_dir }}/{{ item }}" state=directory
with_items:
- conf.d
- sites-available
- sites-enabled
- name: STAT | Check fastcgi.conf
stat: path={{ nginx_etc_dir }}/fastcgi.conf
register: conf
- name: COPY | config
command: "cp {{ nginx_etc_dir }}/fastcgi_params {{ nginx_etc_dir }}/fastcgi.conf"
when: not conf.stat.exists
notify: reload nginx
- name: LINEINFILE | Add fastcgi config
lineinfile: >
line="fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;"
dest="{{ nginx_etc_dir }}/fastcgi.conf"
notify: reload nginx
- name: COPY | Populate proxy_params
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;"
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

View File

@@ -1,7 +1,10 @@
--- ---
- name: INCLUDE_VARS | Related to OS
include_vars: "{{ ansible_distribution }}.yml"
- name: INCLUDE | Install - name: INCLUDE | Install
include: install.yml include: install_{{ ansible_distribution }}.yml
- name: INCLUDE | Prepare - name: INCLUDE | Prepare
include: prepare.yml include: prepare.yml

View File

@@ -2,14 +2,22 @@
- name: SHELL | Get Nginx version - name: SHELL | Get Nginx version
shell: nginx -v 2>&1 | sed -r 's#.*/##;' | cut -d ' ' -f 1 shell: nginx -v 2>&1 | sed -r 's#.*/##;' | cut -d ' ' -f 1
args:
executable: /bin/sh
register: nginx_version register: nginx_version
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 -r 's/_module\s*$//g' |sort shell: nginx -V 2>&1 | tr -- - '\n' | grep -A 1 with | grep _module | sed 's/_module[[:space:]]*//g' | sort
register: nginx_modules args:
executable: /bin/sh
register: shell_modules
changed_when: false changed_when: false
- name: SET_FACT | Save modules
set_fact:
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 }} owner=root mode=0755 state=directory
with_items: "{{ nginx_dirs }}" with_items: "{{ nginx_dirs }}"

View File

@@ -18,14 +18,14 @@
file: > file: >
path="{{ nginx_ssl_dir + '/' + item.name }}" path="{{ nginx_ssl_dir + '/' + item.name }}"
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
- 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 }}"
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
@@ -33,7 +33,7 @@
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 }}"
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

View File

@@ -1,11 +1,24 @@
--- ---
- name: TEMPLATE | Deploy PHP upstream to Nginx - name: TEMPLATE | Deploy PHP upstream to Nginx
template: src=etc/nginx/upstream/php.conf.j2 dest=/etc/nginx/conf.d/php.conf template: >
when: nginx_php src=etc/nginx/upstream/php.conf.j2
dest="{{ nginx_etc_dir }}/conf.d/php.conf"
when: nginx_php56 or nginx_php70
notify: reload nginx notify: reload nginx
- name: TEMPLATE | Deploy other upstreams - name: TEMPLATE | Deploy other upstreams
template: src=etc/nginx/upstream/upstream.conf.j2 dest=/etc/nginx/conf.d/upstream-{{ item.name }}.conf template: >
with_items: nginx_upstreams src=etc/nginx/upstream/upstream.conf.j2
dest={{ nginx_etc_dir }}/conf.d/upstream-{{ item.name }}.conf
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

View File

@@ -1,40 +1,38 @@
--- ---
- name: FAIL | Check filenames
fail: msg="Forbidden keyword default on vhost {{ item.name if item.name is string else item.name[0] }}"
when: item.filename is defined and item.filename == 'default'
with_items: "{{ nginx_vhosts }}"
- name: FAIL | Check vhost and SSL/TLS support - 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] }}" fail: msg="Missmatch configuration for vhost {{ item.name if item.name is string else item.name[0] }}"
when: > when: >
item.proto is defined and item.proto is defined and
'https' in item.proto and 'https' in item.proto and
item.ssl_name is not defined item.ssl_name is not defined
with_items: nginx_vhosts with_items: "{{ nginx_vhosts }}"
- name: FAIL | Check HTTPS redir and proto
fail: msg="You can't have HTTP proto and HTTPS redirection at the same time"
when: >
((item.proto is defined and 'http' in item.proto) or (item.proto is not defined)) and
(item.redirect_http is defined and item.redirect_http)
with_items: "{{ nginx_vhosts }}"
- name: FILE | Create root directory - name: FILE | Create root directory
file: > file: >
path={{ nginx_root }} path={{ nginx_root }}
state=directory 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 not in nginx_templates_no_dir) 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) - 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
owner={{ item.owner | default('www-data') }} owner={{ item.owner | default(nginx_user) }}
group={{ item.group | default('www-data') }} group={{ item.group | default(nginx_user) }}
mode={{ item.mode | default('0755') }} mode={{ item.mode | default('0755') }}
with_items: nginx_vhosts with_items: "{{ nginx_vhosts }}"
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
@@ -44,50 +42,46 @@
- name: TEMPLATE | Create vhosts - name: TEMPLATE | Create vhosts
template: > template: >
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=/etc/nginx/sites-available/{{ 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.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 - name: FILE | Delete vhosts
file: path=/etc/nginx/sites-available/{{ item.name if item.name is string else item.name[0] }} state=absent file: path={{ nginx_etc_dir }}/sites-available/{{ 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.delete is defined and item.delete when: item.delete is defined and item.delete
- name: FILE | Enable vhosts - name: FILE | Enable vhosts
file: > file: >
src=/etc/nginx/sites-available/{{ item.name if item.name is string else item.name[0] }} src={{ nginx_etc_dir }}/sites-available/{{ item.filename | default(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] }} 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.enable is not defined) or
(item.enable is defined and item.enable)) and (item.enable is defined and item.enable)) and
(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: path=/etc/nginx/sites-enabled/{{ 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.enable is defined and not item.enable) or (item.delete is defined and item.delete)
- name: FILE | Delete default vhost when explicitely defined - name: FILE | Delete default vhost when explicitely defined
file: > file: >
path=/etc/nginx/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
file: > file: >
src=/etc/nginx/sites-available/default src={{ nginx_etc_dir }}/sites-available/default
dest=/etc/nginx/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

View File

@@ -2,13 +2,11 @@
# {{ ansible_managed }} # {{ ansible_managed }}
# #
ssl_ciphers "ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4"; ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH:ECDHE-RSA-AES128-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA128:DHE-RSA-AES128-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES128-GCM-SHA128:ECDHE-RSA-AES128-SHA384:ECDHE-RSA-AES128-SHA128:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES128-SHA128:DHE-RSA-AES128-SHA128:DHE-RSA-AES128-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA384:AES128-GCM-SHA128:AES128-SHA128:AES128-SHA128:AES128-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4";
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on; ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m; ssl_session_cache shared:SSL:10m;
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains"; add_header Strict-Transport-Security "max-age=63072000; includeSubDomains"{% if nginx_version.stdout | version_compare('1.7.5', 'ge') %} always{% endif %};
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
{% if nginx_version.stdout | version_compare('1.3.7', 'ge') %} {% if nginx_version.stdout | version_compare('1.3.7', 'ge') %}
ssl_stapling on; ssl_stapling on;
ssl_stapling_verify on; ssl_stapling_verify on;

View File

@@ -2,13 +2,11 @@
# {{ ansible_managed }} # {{ ansible_managed }}
# #
ssl_ciphers "AES256+EECDH:AES256+EDH"; ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on; ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m; ssl_session_cache shared:SSL:10m;
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains"; add_header Strict-Transport-Security "max-age=63072000; includeSubDomains"{% if nginx_version.stdout | version_compare('1.7.5', 'ge') %} always{% endif %};
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
{% if nginx_version.stdout | version_compare('1.3.7', 'ge') %} {% if nginx_version.stdout | version_compare('1.3.7', 'ge') %}
ssl_stapling on; ssl_stapling on;
ssl_stapling_verify on; ssl_stapling_verify on;

View File

@@ -14,7 +14,7 @@ events {
http { http {
types_hash_max_size {{ nginx_http_types_hash_max_size }}; types_hash_max_size {{ nginx_http_types_hash_max_size }};
include /etc/nginx/mime.types; include {{ nginx_etc_dir }}/mime.types;
default_type {{ nginx_http_default_type }}; default_type {{ nginx_http_default_type }};
access_log {{ nginx_http_access_log }}; access_log {{ nginx_http_access_log }};
@@ -45,8 +45,8 @@ http {
gzip_vary {{ nginx_http_gzip_vary }}; gzip_vary {{ nginx_http_gzip_vary }};
gzip_disable {{ nginx_http_gzip_disable }}; gzip_disable {{ nginx_http_gzip_disable }};
include /etc/nginx/conf.d/*.conf; include {{ nginx_etc_dir }}/conf.d/*.conf;
include /etc/nginx/sites-enabled/*; include {{ nginx_etc_dir }}/sites-enabled/*;
} }
# vim:filetype=nginx # vim:filetype=nginx

View File

@@ -25,7 +25,7 @@
{% block template_upstream_location %} {% block template_upstream_location %}
location ~ \.cgi$ { location ~ \.cgi$ {
gzip off; gzip off;
include /etc/nginx/fastcgi_params; include {{ nginx_etc_dir }}/fastcgi_params;
fastcgi_pass unix:/var/run/fcgiwrap.socket; fastcgi_pass unix:/var/run/fcgiwrap.socket;
fastcgi_index BackupPC_Admin; fastcgi_index BackupPC_Admin;
fastcgi_param SCRIPT_FILENAME /usr/share/backuppc/cgi-bin$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME /usr/share/backuppc/cgi-bin$fastcgi_script_name;

View File

@@ -3,6 +3,7 @@
{% 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 __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' }) %}
{% 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 }}";
@@ -30,10 +31,12 @@ server {
{% 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.stdout_lines %}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 %};
{% endfor %} {% endfor %}
{{ ssl(item.ssl_name) }} {{ ssl(item.ssl_name) }}
{% 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 %}
server_name {% if item.name is string %}{{ item.name }}{% else %}{{ item.name | join(' ') }}{% endif %}; server_name {% if item.name is string %}{{ item.name }}{% else %}{{ item.name | join(' ') }}{% endif %};
{% block root %} {% block root %}
@@ -47,16 +50,26 @@ 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) }}
{% endif %} {% endif %}
{% block template_headers %}
# --> Custom headers
{% for key, value in __headers.iteritems() %}
add_header {{ key }} {{ value | replace(' always', '') }}{% if nginx_version.stdout | version_compare('1.7.5', 'ge') and ' always' in value %} always{% endif %};
{% endfor %}
# <-- Custom headers
{% endblock %}
{% if not __location.has_key('/') %} {% if not __location.has_key('/') %}
location / { location / {
{% block template_try_files %} {% block template_try_files %}
@@ -70,6 +83,19 @@ server {
{% block template_custom_location %} {% block template_custom_location %}
{% 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 %}
{% 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 {
@@ -89,31 +115,36 @@ server {
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% if __location is iterable and __location | length > 0 %} {% if item.use_access_log is defined %}
# --> Custom locations {% if item.use_access_log %}
{% 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 and item.use_access_log %}
access_log {{ nginx_log_dir }}/{{ __main_name }}_access.log combined; access_log {{ nginx_log_dir }}/{{ __main_name }}_access.log combined;
{% else %} {% else %}
access_log off; access_log off;
{% endif %} {% endif %}
{% if item.use_error_log is defined and item.use_error_log %} {% endif %}
{% if item.use_error_log is defined %}
{% if item.use_error_log %}
error_log {{ nginx_log_dir }}/{{ __main_name }}_error.log {{ nginx_error_log_level }}; error_log {{ nginx_log_dir }}/{{ __main_name }}_error.log {{ nginx_error_log_level }};
{% else %} {% else %}
error_log off; error_log off;
{% endif %} {% endif %}
{% endif %}
} }
{% if item.redirect_https is defined and item.redirect_https %}
#
# Redirect HTTP to HTTPS
#
server {
{% for port in __listen %}
listen {{ port }};
{% endfor %}
server_name {% if item.name is string %}{{ item.name }}{% else %}{{ item.name | join(' ') }}{% endif %};
return 301 https://{{ __main_name }}{% if '443' not in __listen_ssl %}:__listen_ssl[0]{% endif %}$request_uri;
}
{% endif %}
{% if item.redirect_from is defined and item.redirect_from is iterable %} {% if item.redirect_from is defined and item.redirect_from is iterable %}
# #
# Redirect from # Redirect from

View File

@@ -1,7 +1,7 @@
{% extends "_base.j2" %} {% extends "_php.j2" %}
{% block root %} {% block root %}
root /usr/share/nagios3/htdocs; root {{ nginx_nagios_root }};
{% endblock %} {% endblock %}
{% block template_try_files %} {% block template_try_files %}
@@ -11,32 +11,52 @@
index index.php index.html; index index.php index.html;
{% endblock %} {% endblock %}
{% block template_headers %}
# --> Custom headers
{% for key, value in __headers.iteritems() %}
{% if key == "X-Frame-Options" %}
# X-Frame-Options forced by Ansible
add_header {{ key }} SAMEORIGIN{% if nginx_version.stdout | version_compare('1.7.5', 'ge') %} always{% endif %};
{% else %}
add_header {{ key }} {{ value | replace(' always', '') }}{% if nginx_version.stdout | version_compare('1.7.5', 'ge') and ' always' in value %} always{% endif %};
{% endif %}
{% endfor %}
# <-- Custom headers
{% endblock %}
{% block template_local_content %} {% block template_local_content %}
location ~ /\.ht { location ~ /\.ht {
deny all; deny all;
} }
location /stylesheets { location /stylesheets {
alias /etc/nagios3/stylesheets; {% if nginx_nagios_stylesheets is defined %}
alias {{ nginx_nagios_stylesheets }};
{% endif %}
expires 60d; expires 60d;
} }
{% endblock %} {% endblock %}
{% block template_upstream_location %} {% block template_upstream_location %}
{% if ansible_distribution == 'Debian' %}
location /cgi-bin/nagios3 { location /cgi-bin/nagios3 {
root /usr/lib; root /usr/lib;
{% elif ansible_distribution == 'FreeBSD' %}
location /cgi-bin {
{% endif %}
try_files $uri =404; try_files $uri =404;
{% 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;
{% else %} {% else %}
include fastcgi.conf; include fastcgi.conf;
{% endif %} {% endif %}
fastcgi_pass unix:/var/run/fcgiwrap.socket; fastcgi_pass unix:{{ nginx_fcgiwrap_sock }};
fastcgi_param AUTH_USER $remote_user; fastcgi_param AUTH_USER $remote_user;
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;

View 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 %}

View File

@@ -1,4 +1,24 @@
{% extends "_base.j2" %} {% extends "_base.j2" %}
{% macro phpv(version) %}
{% if version == 56 %}
{{ nginx_upstream_php56 -}}
{% elif version == 70 %}
{{ 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 %}

View File

@@ -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 %}

View File

@@ -7,7 +7,7 @@
{% endblock %} {% endblock %}
{% block template_try_files %} {% block template_try_files %}
include /etc/nginx/proxy_params; include {{ nginx_etc_dir }}/proxy_params;
proxy_pass http://{{ item.upstream_name }}; proxy_pass http://{{ item.upstream_name }};
{% if item.proxy_params is defined and item.proxy_params is iterable %} {% if item.proxy_params is defined and item.proxy_params is iterable %}
{% for param in item.proxy_params %} {% for param in item.proxy_params %}

View File

@@ -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

View File

@@ -1,4 +0,0 @@
FROM williamyeh/ansible:debian7-onbuild
RUN apt-get update
CMD ["sh", "tests/test.sh"]

View File

@@ -0,0 +1,11 @@
---
- name: APT | Install web apps
apt: pkg={{ item }} state=present install_recommends=no
with_items:
- backuppc
- nagios3
# - owncloud
- name: SERVICE | Ensure backuppc is started
service: name=backuppc state=started

View File

@@ -0,0 +1,31 @@
---
- name: APT | Install web apps
pkgng: pkg={{ item }} state=present
with_items:
- nagios
- backuppc
- name: COMMAND | Activate backuppc config
command: >
cp /usr/local/etc/backuppc/config.pl.sample /usr/local/etc/backuppc/config.pl
creates=/usr/local/etc/backuppc/config.pl
- name: FILE | Fix backuppc permissions
file: >
path=/usr/local/etc/backuppc/config.pl
owner=backuppc
group=backuppc
- name: FILE | Fix fcgiwrap permission
file: >
path={{ nginx_fcgiwrap_sock }}
mode=0640
owner={{ nginx_user }}
group={{ nginx_user }}
#
# We don't manage BackupPC on FreeBSD... too dirty. :/
#
#- name: SERVICE | Ensure backuppc is started
# service: name=backuppc state=started enabled=yes

View File

@@ -0,0 +1,36 @@
---
- name: APT_REPOSITORY | Install backports
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'
- name: APT | Install needed packages
apt: pkg={{ item }} update_cache=yes cache_valid_time=3600 state=present
with_items:
- curl
- fcgiwrap
- nghttp2
- php5-fpm
- php5-sqlite
- php7.0-fpm
- php7.0-sqlite3
- strace
- vim
- name: SERVICE | Force start services
service: name={{ item }} state=started
register: sf
with_items:
- php5-fpm
- php7.0-fpm
- fcgiwrap

View File

@@ -0,0 +1,25 @@
---
- name: SET_FACT | FreeBSD web user
set_fact:
nginx_pkgng_package: 'nginx-devel'
nginx_user: 'www'
nginx_php70: false
nginx_php56_sockets:
- host: '127.0.0.1'
port: 9000
- name: PKGNG | Install needed packages
pkgng: pkg={{ item }} state=present
with_items:
- php56
- curl
- fcgiwrap
- nghttp2
- name: SERVICE | Force start services
service: name={{ item }} state=started enabled=yes
register: sf
with_items:
- php-fpm
- fcgiwrap

View File

@@ -1 +0,0 @@
localhost

View File

@@ -3,19 +3,18 @@
# Thanks to https://servercheck.in/blog/testing-ansible-roles-travis-ci-github # Thanks to https://servercheck.in/blog/testing-ansible-roles-travis-ci-github
DIR=$( dirname $0 ) DIR=$( dirname $0 )
INVENTORY_FILE="$DIR/inventory"
PLAYBOOK="$DIR/test.yml" PLAYBOOK="$DIR/test.yml"
set -ev set -ev
# Check syntax # Check syntax
ansible-playbook -i $INVENTORY_FILE -c local --syntax-check -vv $PLAYBOOK ansible-playbook -i localhost, -c local --syntax-check -vv $PLAYBOOK
# Check role # Check role
ansible-playbook -i $INVENTORY_FILE -c local --sudo -vv $PLAYBOOK ansible-playbook -i localhost, -c local --sudo -vv $PLAYBOOK
# Check indempotence # Check indempotence
ansible-playbook -i $INVENTORY_FILE -c local --sudo -vv $PLAYBOOK \ ansible-playbook -i localhost, -c local --sudo -vv $PLAYBOOK \
| grep -q 'changed=0.*failed=0' \ | grep -q 'changed=0.*failed=0' \
&& (echo 'Idempotence test: pass' && exit 0) \ && (echo 'Idempotence test: pass' && exit 0) \
|| (echo 'Idempotence test: fail' && exit 1) || (echo 'Idempotence test: fail' && exit 1)

View File

@@ -2,23 +2,8 @@
- hosts: all - hosts: all
pre_tasks: pre_tasks:
- name: APT_REPOSITORY | Install backports - name: INCLUDE | Pre_tasks related to OS version
apt_repository: repo='deb http://httpredir.debian.org/debian {{ ansible_distribution_release }}-backports main' state=present include: "includes/pre_{{ ansible_distribution }}.yml"
- name: APT | Install needed packages
apt: pkg={{ item }} update_cache=yes cache_valid_time=3600 state=present
with_items:
- php5-fpm
- curl
- fcgiwrap
- name: SERVICE | Force start services
service: name={{ item }} state=started
register: sf
with_items:
- php5-fpm
- fcgiwrap
- name: PAUSE | Prevent bugs (CGI not fully loaded)
pause: seconds=5
when: sf.changed
- name: FILE | Create an internal SSL dir - name: FILE | Create an internal SSL dir
file: path={{ int_ansible_ssl_dir }} state=directory file: path={{ int_ansible_ssl_dir }} state=directory
- name: COPY | Deploy test certificate - name: COPY | Deploy test certificate
@@ -29,8 +14,11 @@
# Internal vars # Internal vars
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_apt_package: 'nginx-extras'
nginx_backports: true nginx_backports: true
nginx_php: true nginx_php56: true
nginx_php70: true
nginx_upstreams: nginx_upstreams:
- name: 'test' - name: 'test'
servers: servers:
@@ -38,6 +26,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!'
@@ -119,23 +114,30 @@
- 'test-alias.local' - 'test-alias.local'
- 'test2-alias.local' - 'test2-alias.local'
template: '_base' template: '_base'
filename : 'first-test'
override_try_files: '$uri $uri index.htm index.html' override_try_files: '$uri $uri index.htm index.html'
headers:
'X-Frame-Options': 'deny always'
'X-ansible-default': '1'
manage_local_content: false manage_local_content: false
use_error_log: false
more: more:
- 'autoindex off;' - 'autoindex off;'
- 'add_header X-ansible-default 1;'
location: location:
'/test': '/test':
- 'return 403;' - 'return 403;'
'/gunther': '/gunther':
- 'return 404;' - 'return 404;'
'/status':
- 'stub_status on;'
- 'access_log off;'
- 'allow 127.0.0.1;'
- 'deny all;'
- name: 'test-htpasswd.local' - name: 'test-htpasswd.local'
template: '_base' template: '_base'
location: location:
'/hello': '/hello':
- htpasswd: 'hello' - htpasswd: 'hello'
- 'default_type "text/html; charset=UTF-8";'
- 'echo hello;'
- name: 'test-htpasswd-all.local' - name: 'test-htpasswd-all.local'
template: '_base' template: '_base'
htpasswd: 'hello' htpasswd: 'hello'
@@ -145,11 +147,14 @@
'/': '/':
- 'alias /var/tmp;' - 'alias /var/tmp;'
- name: 'test-php.local' - name: 'test-php.local'
php_version: 70
upstream_params: upstream_params:
- 'fastcgi_param FOO bar;' - 'fastcgi_param FOO bar;'
redirect_from: redirect_from:
- 'www.test-php.local' - 'www.test-php.local'
template: '_php' template: '_php'
use_error_log: true
use_access_log: true
- name: 'test-php-index.local' - name: 'test-php-index.local'
template: '_php_index' template: '_php_index'
- name: 'test-proxy.local' - name: 'test-proxy.local'
@@ -157,8 +162,8 @@
- 8080 - 8080
template: '_proxy' template: '_proxy'
upstream_name: 'test' upstream_name: 'test'
more: headers:
- 'add_header X-proxyfied 1;' 'X-proxyfied': '1'
- name: 'deleted.local' - name: 'deleted.local'
delete: true delete: true
- name: 'redirect-to.local' - name: 'redirect-to.local'
@@ -177,8 +182,16 @@
proto: ['http', 'https'] proto: ['http', 'https']
template: '_base' template: '_base'
ssl_name: 'test-ssl-predeployed.local' ssl_name: 'test-ssl-predeployed.local'
more: headers:
- 'add_header X-ansible-default 1;' 'X-ansible-default': '1'
ssl_template: false
- name: 'test-ssl-redirect.local'
proto: ['https']
template: '_base'
ssl_name: 'test-ssl.local'
redirect_https: true
# - name: 'owncloud.local'
# template: '_owncloud'
nginx_dh_length: 1024 nginx_dh_length: 1024
roles: roles:
- ../../ - ../../
@@ -186,14 +199,8 @@
# -------------------------------- # --------------------------------
# Apps # Apps
# -------------------------------- # --------------------------------
- name: APT | Install web apps - name: INCLUDE | Post_tasks related to OS version
apt: pkg={{ item }} state=present include: "includes/post_{{ ansible_distribution }}.yml"
with_items:
- nagios3
- backuppc
- name: SERVICE | Ensure backuppc is started
service: name=backuppc state=started
# -------------------------------- # --------------------------------
# Deploy index files # Deploy index files
# -------------------------------- # --------------------------------
@@ -203,13 +210,16 @@
- 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 }}/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']
- name: -- Create directory --
file: path={{ nginx_root }}/test-htpasswd.local/public/hello state=directory
- name: -- Add HTML file hello --
copy: dest="{{ nginx_root }}/test-htpasswd.local/public/hello/index.html" content="hello\n"
# -------------------------------- # --------------------------------
# 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.delete is undefined or not item.delete
changed_when: false changed_when: false
- name: -- VERIFY FORBIDDEN -- - name: -- VERIFY FORBIDDEN --
@@ -219,7 +229,7 @@
changed_when: false changed_when: false
- 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.delete is undefined or not item.delete)
changed_when: false changed_when: false
register: r register: r
@@ -235,21 +245,35 @@
failed_when: p.stdout.find('PHP Version') == -1 failed_when: p.stdout.find('PHP Version') == -1
with_items: ['test-php.local', 'test-php-index.local'] with_items: ['test-php.local', 'test-php-index.local']
- name: -- VERIFY PHP5 VHOSTS (implicit default) --
command: "curl -H 'Host: {{ item }}' http://127.0.0.1/"
register: p
changed_when: false
failed_when: p.stdout.find('PHP Version 5') == -1
with_items: ['test-php-index.local']
- 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']
# -------------------------------- # --------------------------------
# Basic Auth # Basic Auth
# -------------------------------- # --------------------------------
- name: -- VERIFY AUTH BASIC NONE -- - name: -- VERIFY AUTH BASIC NONE --
command: "curl -H 'Host: test-htpasswd.local' http://127.0.0.1/hello" command: "curl -H 'Host: test-htpasswd.local' http://127.0.0.1/hello/"
changed_when: false changed_when: false
register: authnone register: authnone
failed_when: authnone.stdout.find('401 Authorization Required') == -1 failed_when: authnone.stdout.find('401 Authorization Required') == -1
- name: -- VERIFY AUTH BASIC FAIL -- - name: -- VERIFY AUTH BASIC FAIL --
command: "curl -u fail:fail -H 'Host: test-htpasswd.local' http://127.0.0.1/hello" command: "curl -u fail:fail -H 'Host: test-htpasswd.local' http://127.0.0.1/hello/"
changed_when: false changed_when: false
register: authfail register: authfail
failed_when: authfail.stdout.find('401 Authorization Required') == -1 failed_when: authfail.stdout.find('401 Authorization Required') == -1
- name: -- VERIFY AUTH BASIC OK -- - name: -- VERIFY AUTH BASIC OK --
command: "curl -u hanx:qwerty -H 'Host: test-htpasswd.local' http://127.0.0.1/hello" command: "curl -u hanx:qwerty -H 'Host: test-htpasswd.local' http://127.0.0.1/hello/"
changed_when: false changed_when: false
register: authok register: authok
failed_when: authok.stdout.find('hello') == -1 failed_when: authok.stdout.find('hello') == -1
@@ -272,6 +296,7 @@
changed_when: false changed_when: false
register: authbpc register: authbpc
failed_when: authbpc.stdout.find('BackupPC Server Status') == -1 failed_when: authbpc.stdout.find('BackupPC Server Status') == -1
when: ansible_distribution != 'FreeBSD'
# -------------------------------- # --------------------------------
# Nagios # Nagios
@@ -282,11 +307,32 @@
register: nagios_php register: nagios_php
failed_when: nagios_php.stdout.find('Nagios Core') == -1 failed_when: nagios_php.stdout.find('Nagios Core') == -1
- name: -- VERIFY NAGIOS3 CGI -- - name: -- VERIFY NAGIOS3 CGI --
command: "curl -u nagiosadmin:nagios -H 'Host: nagios3.local' http://127.0.0.1/cgi-bin/nagios3/summary.cgi" command: "curl -u nagiosadmin:nagios -H 'Host: nagios3.local' http://127.0.0.1/cgi-bin{% if ansible_distribution == 'Debian' %}/nagios3{% endif %}/summary.cgi"
changed_when: false changed_when: false
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
# -------------------------------- # --------------------------------
@@ -298,6 +344,15 @@
with_items: with_items:
- 'test-ssl-predeployed.local' - 'test-ssl-predeployed.local'
- 'test-ssl.local' - 'test-ssl.local'
- name: -- VERIFY SSL REDIRECT --
command: "curl -v --insecure -H 'Host: {{ item }}' http://127.0.0.1/"
changed_when: false
register: sslredirok
failed_when: >
sslredirok.stderr.find('< Location') == -1 and
sslredirok.stderr.find('https://{{ item }}/') == -1
with_items:
- 'test-ssl-redirect.local'
# -------------------------------- # --------------------------------
# Default vhosts # Default vhosts
@@ -326,3 +381,20 @@
changed_when: false changed_when: false
register: notdefaultssl register: notdefaultssl
failed_when: notdefaultssl.stderr.find('X-ansible-default') != -1 failed_when: notdefaultssl.stderr.find('X-ansible-default') != -1
- name: -- VERIFY DEFAULT VHOST + STUB_STATUS --
command: "curl -v http://127.0.0.1/status"
changed_when: false
register: vdefault_status
failed_when: >
vdefault_status.stderr.find('X-ansible-default') == -1 or
vdefault_status.stdout.find('Active connections') == -1
# --------------------------------
# Check HTTP2
# --------------------------------
- name: SHELL | Check HTTP2
shell: nghttp -nv https://localhost 2> /dev/null | grep -q h2
args:
executable: /bin/sh
changed_when: false
when: nginx_auto_config_httpv2 and 'http_v2' in nginx_modules

8
vars/Debian.yml Normal file
View File

@@ -0,0 +1,8 @@
nginx_events_use: 'epoll'
nginx_pid: '/run/nginx.pid'
nginx_etc_dir: '/etc/nginx'
# Specific vhosts
nginx_nagios_root: '/usr/share/nagios3/htdocs'
nginx_nagios_stylesheets: '/etc/nagios3/stylesheets'
nginx_fcgiwrap_sock: '/var/run/fcgiwrap.socket'

7
vars/FreeBSD.yml Normal file
View File

@@ -0,0 +1,7 @@
nginx_events_use: 'kqueue'
nginx_pid: '/var/run/nginx.pid'
nginx_etc_dir: '/usr/local/etc/nginx'
# Specific vhosts
nginx_nagios_root: '/usr/local/www/nagios'
nginx_fcgiwrap_sock: '/var/run/fcgiwrap/fcgiwrap.sock'

View File

@@ -28,6 +28,10 @@ nginx_dirs:
- "{{ nginx_helper_dir }}" - "{{ nginx_helper_dir }}"
nginx_templates_no_dir: nginx_templates_no_dir:
- '_proxy'
- '_nagios3'
- '_backuppc' - '_backuppc'
- '_nagios3'
- '_owncloud'
- '_proxy'
nginx_upstream_php56: 'php56'
nginx_upstream_php70: 'php70'