mirror of
https://github.com/HanXHX/ansible-nginx.git
synced 2026-02-28 09:22:10 +07:00
Compare commits
213 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a4aeec0a94 | ||
|
|
713a2241de | ||
|
|
6cae501266 | ||
|
|
dd7834e8ce | ||
|
|
cb031c4014 | ||
|
|
db97fe84f8 | ||
|
|
c9629e385f | ||
|
|
5843d695b3 | ||
|
|
8c7d581131 | ||
|
|
0b85d81991 | ||
|
|
7fe08beb9a | ||
|
|
33ef161623 | ||
|
|
c2685732a4 | ||
|
|
737dfbeb30 | ||
|
|
def13392a7 | ||
|
|
6897f66344 | ||
|
|
552999c782 | ||
|
|
fe32f8d40a | ||
|
|
5d46daaba8 | ||
|
|
4ca8f9e319 | ||
|
|
d3d9b5c296 | ||
|
|
45886ca9cc | ||
|
|
bb74ac804e | ||
|
|
2a5a1701f3 | ||
|
|
a1866f806f | ||
|
|
0788b6c84f | ||
|
|
222998839c | ||
|
|
d00f3301e1 | ||
|
|
8f76b9c68c | ||
|
|
8dca6c8404 | ||
|
|
a01f6cd5ea | ||
|
|
609e4f013d | ||
|
|
c79d370ad6 | ||
|
|
45f800fe18 | ||
|
|
9fc4838b1b | ||
|
|
3304934227 | ||
|
|
57968b50c0 | ||
|
|
8675d683ec | ||
|
|
10bd837f54 | ||
|
|
332e28a9d7 | ||
|
|
4b3b857733 | ||
|
|
608784ca55 | ||
|
|
36652f4742 | ||
|
|
463ce45105 | ||
|
|
70283ddcc6 | ||
|
|
de40c07ac5 | ||
|
|
54dd1ef3c0 | ||
|
|
cfe27ef245 | ||
|
|
6f098475e5 | ||
|
|
090875cbde | ||
|
|
b72263f7e5 | ||
|
|
4751eaa3c1 | ||
|
|
e83395271d | ||
|
|
6935404939 | ||
|
|
acf8de8f87 | ||
|
|
50e25d45b8 | ||
|
|
adf53b0d95 | ||
|
|
4d819ac2a1 | ||
|
|
af9fa6a2c3 | ||
|
|
4486bddb19 | ||
|
|
0b99a1c28e | ||
|
|
d616657f12 | ||
|
|
eb0bdcad6f | ||
|
|
3ae791ec47 | ||
|
|
cbdfc741ba | ||
|
|
a60e81cc1f | ||
|
|
f1af8991fd | ||
|
|
fcb59fd331 | ||
|
|
2aa9e8b6b9 | ||
|
|
7892626fc0 | ||
|
|
ae167d3317 | ||
|
|
d8f241f79c | ||
|
|
0e33d1b372 | ||
|
|
2cd559b87a | ||
|
|
d550f1bab1 | ||
|
|
021ca4e173 | ||
|
|
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 | ||
|
|
d49e41652c | ||
|
|
9b19231d8b | ||
|
|
80d1d82acc | ||
|
|
5445d66172 | ||
|
|
9a5afd09fa | ||
|
|
96e406c791 | ||
|
|
02994af5ee | ||
|
|
ee79ec9845 | ||
|
|
2ba906be2e | ||
|
|
d223f8b144 | ||
|
|
8f837de390 | ||
|
|
aa4bc8d6a7 | ||
|
|
2fcf7fa701 | ||
|
|
91686fc266 | ||
|
|
5e493c15ac | ||
|
|
97aeda5678 | ||
|
|
3666b29184 | ||
|
|
9b5f136510 | ||
|
|
7cc44bc009 | ||
|
|
078c3420e1 | ||
|
|
2cfda9a930 | ||
|
|
29a40fc0a8 | ||
|
|
33f34a0550 | ||
|
|
8fc6f7117e | ||
|
|
972555ce22 | ||
|
|
2f0672359d | ||
|
|
cdc152afbe | ||
|
|
729b621ccb | ||
|
|
c13cb0d770 | ||
|
|
8edd69547d | ||
|
|
791832f6d1 | ||
|
|
e00313bb36 | ||
|
|
44a5c31b12 | ||
|
|
232e63dffe | ||
|
|
fe68e17663 | ||
|
|
ac61b3df0a | ||
|
|
1071881ac2 | ||
|
|
e139ab3e35 | ||
|
|
1f82e7adfe | ||
|
|
e43a958b03 | ||
|
|
47c24a2eb3 | ||
|
|
82c44be932 | ||
|
|
781008dfff | ||
|
|
26a50945c5 | ||
|
|
4dc28d9471 | ||
|
|
3231e58bc0 | ||
|
|
d4f9b6f710 | ||
|
|
d049be0d81 | ||
|
|
863dc6ca76 | ||
|
|
1338e4dee6 | ||
|
|
dd97e5ec79 | ||
|
|
7f56db76e0 | ||
|
|
51a1105dff | ||
|
|
0a8f21b0b7 | ||
|
|
75d815b4a4 | ||
|
|
520eed50c3 | ||
|
|
c36c4824b7 | ||
|
|
c357658c25 | ||
|
|
be349ec686 | ||
|
|
287d154532 | ||
|
|
11c98ab145 | ||
|
|
ef5a7bf756 | ||
|
|
2f6f2d4362 | ||
|
|
53b9dc078e | ||
|
|
ccba868390 | ||
|
|
9b6523a0b1 | ||
|
|
883948f081 | ||
|
|
ad9c0fa979 | ||
|
|
8a30223bb9 | ||
|
|
49f11751e6 | ||
|
|
f64e1f1106 | ||
|
|
d463b690ec | ||
|
|
7c9c7ab474 | ||
|
|
c703a4fba8 | ||
|
|
e0bb5e2752 | ||
|
|
05cb864c7c | ||
|
|
f8d138828b | ||
|
|
1d86ed9a40 | ||
|
|
f9127f9a40 | ||
|
|
88d1c7fdb7 | ||
|
|
c0f2d694e7 | ||
|
|
0d65cd3c5c | ||
|
|
9779555ac8 | ||
|
|
17905edf30 | ||
|
|
f2c6ec6c57 | ||
|
|
80e3cae22e |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,2 +1,4 @@
|
|||||||
.vagrant*
|
.vagrant*
|
||||||
*.swp
|
*.swp
|
||||||
|
*.retry
|
||||||
|
*.pyc
|
||||||
|
|||||||
50
.travis.yml
50
.travis.yml
@@ -1,13 +1,57 @@
|
|||||||
env:
|
env:
|
||||||
- PLATFORM=debian-wheezy
|
- PLATFORM='docker-debian-jessie' ANSIBLE_VERSION='ansible>=2.2,<2.3'
|
||||||
- PLATFORM=debian-jessie
|
- PLATFORM='docker-debian-jessie-backports' ANSIBLE_VERSION='ansible>=2.2,<2.3'
|
||||||
|
- PLATFORM='docker-debian-jessie-dotdeb' ANSIBLE_VERSION='ansible>=2.2,<2.3'
|
||||||
|
- PLATFORM='docker-debian-jessie' ANSIBLE_VERSION='ansible>=2.3,<2.4'
|
||||||
|
- PLATFORM='docker-debian-jessie-backports' ANSIBLE_VERSION='ansible>=2.3,<2.4'
|
||||||
|
- PLATFORM='docker-debian-jessie-dotdeb' ANSIBLE_VERSION='ansible>=2.3,<2.4'
|
||||||
|
- PLATFORM='docker-debian-stretch' ANSIBLE_VERSION='ansible>=2.3,<2.4'
|
||||||
|
- PLATFORM='docker-debian-stretch-sury' ANSIBLE_VERSION='ansible>=2.3,<2.4'
|
||||||
|
- PLATFORM='docker-debian-jessie' ANSIBLE_VERSION='ansible>=2.4,<2.5'
|
||||||
|
- PLATFORM='docker-debian-jessie-backports' ANSIBLE_VERSION='ansible>=2.4,<2.5'
|
||||||
|
- PLATFORM='docker-debian-jessie-dotdeb' ANSIBLE_VERSION='ansible>=2.4,<2.5'
|
||||||
|
- PLATFORM='docker-debian-stretch' ANSIBLE_VERSION='ansible>=2.4,<2.5'
|
||||||
|
- PLATFORM='docker-debian-stretch-sury' ANSIBLE_VERSION='ansible>=2.4,<2.5'
|
||||||
|
- PLATFORM='docker-debian-jessie' ANSIBLE_VERSION='ansible>=2.5b,<2.6'
|
||||||
|
- PLATFORM='docker-debian-jessie-backports' ANSIBLE_VERSION='ansible>=2.5b,<2.6'
|
||||||
|
- PLATFORM='docker-debian-jessie-dotdeb' ANSIBLE_VERSION='ansible>=2.5b,<2.6'
|
||||||
|
- PLATFORM='docker-debian-stretch' ANSIBLE_VERSION='ansible>=2.5b,<2.6'
|
||||||
|
- PLATFORM='docker-debian-stretch-sury' ANSIBLE_VERSION='ansible>=2.5b,<2.6'
|
||||||
|
|
||||||
|
matrix:
|
||||||
|
allow_failures:
|
||||||
|
- env: PLATFORM='docker-debian-jessie' ANSIBLE_VERSION='ansible>=2.5b,<2.6'
|
||||||
|
- env: PLATFORM='docker-debian-jessie-backports' ANSIBLE_VERSION='ansible>=2.5b,<2.6'
|
||||||
|
- env: PLATFORM='docker-debian-jessie-dotdeb' ANSIBLE_VERSION='ansible>=2.5b,<2.6'
|
||||||
|
- env: PLATFORM='docker-debian-stretch' ANSIBLE_VERSION='ansible>=2.5b,<2.6'
|
||||||
|
- env: PLATFORM='docker-debian-stretch-sury' ANSIBLE_VERSION='ansible>=2.5b,<2.6'
|
||||||
|
|
||||||
|
fast_finish: true
|
||||||
|
|
||||||
sudo: required
|
sudo: required
|
||||||
|
|
||||||
|
dist: trusty
|
||||||
|
|
||||||
language: python
|
language: python
|
||||||
|
|
||||||
services:
|
services:
|
||||||
- docker
|
- docker
|
||||||
|
|
||||||
|
before_install:
|
||||||
|
- wget https://releases.hashicorp.com/vagrant/2.0.1/vagrant_2.0.1_x86_64.deb
|
||||||
|
- sudo dpkg -i vagrant_2.0.1_x86_64.deb
|
||||||
|
|
||||||
|
install:
|
||||||
|
- pip install "$ANSIBLE_VERSION"
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- docker build -f tests/$PLATFORM.Dockerfile -t test-$PLATFORM . && docker run --name $PLATFORM test-$PLATFORM
|
- VAGRANT_DEFAULT_PROVIDER=docker vagrant up $PLATFORM
|
||||||
|
- >
|
||||||
|
VAGRANT_DEFAULT_PROVIDER=docker vagrant provision $PLATFORM
|
||||||
|
| grep -q 'changed=0.*failed=0'
|
||||||
|
&& (echo 'Idempotence test: pass' && exit 0)
|
||||||
|
|| (echo 'Idempotence test: fail' && exit 1)
|
||||||
|
- VAGRANT_DEFAULT_PROVIDER=docker vagrant status
|
||||||
|
|
||||||
|
notifications:
|
||||||
|
webhooks: https://galaxy.ansible.com/api/v1/notifications/
|
||||||
|
|||||||
176
README.md
176
README.md
@@ -1,123 +1,103 @@
|
|||||||
Nginx for Debian 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.
|
Install and configure Nginx on Debian/FreeBSD.
|
||||||
|
|
||||||
SSL management will come later.
|
Features:
|
||||||
|
|
||||||
|
- SSL/TLS "hardened" support
|
||||||
|
- Manage basic auth on site / location
|
||||||
|
- Proxy + Upstream
|
||||||
|
- Fast PHP configuration
|
||||||
|
- Preconfigured site templates (should work on many app)
|
||||||
|
- Auto-configure HTTP2 on SSL/TLS sites
|
||||||
|
- Manage dynamic modules (install and loading)
|
||||||
|
- Deploy custom facts.d with sites config
|
||||||
|
- Can listen with proxy protocol
|
||||||
|
- Generate certificates with acme.sh (let's encrypt) -- *EXPERIMENTAL*
|
||||||
|
|
||||||
|
Supported OS:
|
||||||
|
|
||||||
|
| OS | Working | Stable (active support) |
|
||||||
|
| ------------------ | ------- | ----------------------- |
|
||||||
|
| Debian Jessie (8) | Yes | Yes |
|
||||||
|
| Debian Stretch (9) | Yes | Yes |
|
||||||
|
| FreeBSD 11 | Yes | No |
|
||||||
|
| FreeBSD 12 | Yes | No |
|
||||||
|
|
||||||
Requirements
|
Requirements
|
||||||
------------
|
------------
|
||||||
|
|
||||||
None.
|
None. If you set true to `nginx_backports`, you must install backports repository before lauching this role.
|
||||||
|
|
||||||
Role Variables
|
Role Variables
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
- `nginx_apt_package`: APT nginx package (try: apt-cache search ^nginx)
|
### Packaging
|
||||||
- `nginx_root`: root directory where you want to have your files
|
|
||||||
- `nginx_log_dir`: log directory (if you change it, don't forget to change logrotate config)
|
|
||||||
- `nginx_ssl_dir`: directory where you install your SSL/TLS keys
|
|
||||||
- `nginx_resolver`: list of DNS resolver (default: OpenDNS)
|
|
||||||
- `nginx_error_log_level`: default log level
|
|
||||||
- `nginx_dh_length`: DH key length (default is 2048)
|
|
||||||
|
|
||||||
### PHP
|
Debian:
|
||||||
|
|
||||||
- `nginx_php`: boolean if you need to preconfigure PHP (default: false)
|
- `nginx_apt_package`: APT nginx package (try: apt-cache search ^nginx)
|
||||||
- `nginx_php_sockets`: list of //sockets//
|
- `nginx_backports`: Install nginx from backport repository (bool)
|
||||||
|
|
||||||
You should see [Nginx upstream module doc](http://nginx.org/en/docs/http/ngx_http_upstream_module.html).
|
FreeBSD:
|
||||||
|
|
||||||
Socket:
|
- `nginx_pkgng_package`: PKGNG nginx package (should be "nginx" or "nginx-devel")
|
||||||
- `unix_socket`
|
|
||||||
- `host`
|
### Shared
|
||||||
- `port`
|
|
||||||
- `weight`
|
- `nginx_root`: root directory where you want to have your files
|
||||||
- `max_fails`
|
- `nginx_log_dir`: log directory (if you change it, don't forget to change logrotate config)
|
||||||
- `fail_timeout`
|
- `nginx_resolver`: list of DNS resolver (default: OpenDNS)
|
||||||
|
- `nginx_error_log_level`: default log level
|
||||||
|
- `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
|
||||||
|
|
||||||
- `nginx_user`
|
- `nginx_user`
|
||||||
- `nginx_worker_processes`
|
- `nginx_worker_processes`
|
||||||
- `nginx_events`: key/value in events block
|
- `nginx_pid`: daemon pid file
|
||||||
- `nginx_http`: key/value in http block
|
- `nginx_events_*`: all variables in events block
|
||||||
- `nginx_pid`: daemon pid file
|
- `nginx_http_*`: all variables in http block
|
||||||
|
- `nginx_custom_http`: instructions list (will put data in `/etc/nginx/conf.d/custom.conf`)
|
||||||
|
- `nginx_module_packages`: package list module to install (Debian)
|
||||||
|
- `nginx_load_modules`: module list to load (full path), should be used only on FreeBSD
|
||||||
|
|
||||||
### Vhost management
|
### Misc
|
||||||
|
|
||||||
You can see many examples in: [tests/test.yml](tests/test.yml).
|
- `nginx_debug_role`: set _true_ if you need to see output of no\_log tasks
|
||||||
|
|
||||||
- `nginx_vhosts`: List of dict. A vhost has few keys. See bellow.
|
About modules
|
||||||
|
-------------
|
||||||
|
|
||||||
#### Common
|
Last updates from Debian backports loads modules from /etc/nginx/modules-enabled directory. Disabling/Enabling is not supported anymore. Please wait further update.
|
||||||
|
|
||||||
- `name`: (M) Domain or list of domain used.
|
Fine configuration
|
||||||
- `template`: (M) template used to create vhost. Optional if you set `delete` to true.
|
------------------
|
||||||
- `enable`: (O) Enable the vhost (default is true)
|
|
||||||
- `delete`: (O) Delete the vhost (default is false)
|
|
||||||
- `redirect_from`: (O) Domain list to redirect to the first `name`. You can use this key to redirect non-www to www
|
|
||||||
- `location`: (O) Add new custom locations (it does not overwrite!)
|
|
||||||
- `more`: (O) Add more custom infos.
|
|
||||||
- `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
|
|
||||||
- `manage_local_content`: (O) Boolean. Set to false if you don't want to manage local content (images, css...). This option is useless if you use proxy `template`
|
|
||||||
|
|
||||||
(O) : Optional
|
[Site configuration](doc/site.md)
|
||||||
(M) : Mandatory
|
|
||||||
|
|
||||||
#### Templates
|
[PHP configuration](doc/php.md)
|
||||||
|
|
||||||
- `base`: static template
|
[Upstream Configuration](doc/upstream.md)
|
||||||
- `dokuwiki`
|
|
||||||
- `phalcon`: Phalcon PHP Framework
|
|
||||||
- `php`: PHP base template. Can work with many frameworks/tools
|
|
||||||
- `php_index`: Same as above. But you can only run index.php
|
|
||||||
- `proxy`
|
|
||||||
- `wordpress`
|
|
||||||
|
|
||||||
Templates works as parent-child.
|
[SSL/TLS Configuration](doc/ssl.md)
|
||||||
|
|
||||||
#### About proxy template
|
[Basic Auth](doc/auth.md)
|
||||||
|
|
||||||
Proxy template allow you to use Nginx as reverse proxy. Usefull when you have application serveur such as Redmine, Jenkins...
|
[FreeBSD](doc/freebsd.md)
|
||||||
|
|
||||||
You have many key added to vhost key:
|
[acme.sh](doc/acme.md)
|
||||||
|
|
||||||
- `upstream_name`: (O) upstream name used to pass proxy
|
Note
|
||||||
- `proxy_params`: (M) list of raw params passed to the vhost
|
----
|
||||||
|
|
||||||
(O) : Optional
|
- Active support for Debian.
|
||||||
(M) : Mandatory
|
- 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).
|
||||||
|
|
||||||
### Upstream management
|
|
||||||
|
|
||||||
- `nginx_upstreams`: List of dict. An upstream has few keys. See bellow.
|
|
||||||
|
|
||||||
Note: Few params are unavailable on old Nginx version. But this role don't put it if your version is too old!
|
|
||||||
|
|
||||||
#### Upstream params
|
|
||||||
|
|
||||||
- `name`: upstream name. Can be use in vhost with *proxy_pass http://upstream_name*
|
|
||||||
- `params`: list of param (hash, zone...)
|
|
||||||
- `servers`: each upstream MUST have at least 1 server
|
|
||||||
|
|
||||||
#### Server params
|
|
||||||
|
|
||||||
You must set a `path`. For example: *192.168.0.50:8080* or *unix:/tmp/my.sock*.
|
|
||||||
|
|
||||||
All this params are optional. You should see [Nginx upstream doc](http://nginx.org/en/docs/http/ngx_http_upstream_module.html).
|
|
||||||
|
|
||||||
- `weight`
|
|
||||||
- `max`fails`
|
|
||||||
- `fail`timeout`
|
|
||||||
- `backup`
|
|
||||||
- `down`
|
|
||||||
- `route`
|
|
||||||
- `slow`start`
|
|
||||||
|
|
||||||
Dependencies
|
Dependencies
|
||||||
------------
|
------------
|
||||||
@@ -127,16 +107,28 @@ None
|
|||||||
Example Playbook
|
Example Playbook
|
||||||
----------------
|
----------------
|
||||||
|
|
||||||
- hosts: servers
|
See [tests/test.yml](tests/test.yml).
|
||||||
roles:
|
|
||||||
- { role: HanXHX.nginx }
|
|
||||||
|
|
||||||
License
|
License
|
||||||
-------
|
-------
|
||||||
|
|
||||||
GPLv2
|
GPLv2
|
||||||
|
|
||||||
|
|
||||||
|
Donation
|
||||||
|
--------
|
||||||
|
|
||||||
|
If this code helped you, or if you’ve used them for your projects, feel free to buy me some :beers:
|
||||||
|
|
||||||
|
- Bitcoin: `1BQwhBeszzWbUTyK4aUyq3SRg7rBSHcEQn`
|
||||||
|
- Ethereum: `63abe6b2648fd892816d87a31e3d9d4365a737b5`
|
||||||
|
- Litecoin: `LeNDw34zQLX84VvhCGADNvHMEgb5QyFXyD`
|
||||||
|
- Monero: `45wbf7VdQAZS5EWUrPhen7Wo4hy7Pa7c7ZBdaWQSRowtd3CZ5vpVw5nTPphTuqVQrnYZC72FXDYyfP31uJmfSQ6qRXFy3bQ`
|
||||||
|
|
||||||
|
No crypto-currency? :star: the project is also a way of saying thank you! :sunglasses:
|
||||||
|
|
||||||
Author Information
|
Author Information
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
- Twitter: https://twitter.com/hanxhx
|
- Twitter: [@hanxhx_](https://twitter.com/hanxhx_)
|
||||||
|
|
||||||
|
|||||||
78
Vagrantfile
vendored
78
Vagrantfile
vendored
@@ -5,27 +5,79 @@
|
|||||||
|
|
||||||
Vagrant.configure("2") do |config|
|
Vagrant.configure("2") do |config|
|
||||||
|
|
||||||
vms = [
|
vms_debian = [
|
||||||
[ "debian-wheezy", "deb/wheezy-amd64" , "192.168.33.27" ],
|
{ :name => "debian-jessie", :box => "debian/jessie64", :vars => { "nginx_php": [{"version": "5.6"}] }},
|
||||||
[ "debian-jessie", "deb/jessie-amd64", "192.168.33.28" ]
|
{ :name => "debian-jessie-backports", :box => "debian/jessie64", :vars => { "nginx_php": [{"version": "5.6"}], "nginx_backports": true }},
|
||||||
|
{ :name => "debian-jessie-dotdeb", :box => "debian/jessie64", :vars => { "nginx_php": [{"version": "7.0"}, {"version": "5.6", "upstream_name": "legacy"} ], "dotdeb": true }},
|
||||||
|
{ :name => "debian-stretch", :box => "debian/stretch64", :vars => { "nginx_php": [{"version": "7.0"}] }},
|
||||||
|
{ :name => "debian-stretch-sury", :box => "debian/stretch64", :vars => { "nginx_php": [{"version": "7.1"}], "sury": true }}
|
||||||
]
|
]
|
||||||
|
|
||||||
config.vm.provider "virtualbox" do |v|
|
vms_freebsd = [
|
||||||
v.cpus = 1
|
{ :name => "freebsd-11", :box => "freebsd/FreeBSD-11.1-STABLE", :vars => {} },
|
||||||
v.memory = 256
|
{ :name => "freebsd-12", :box => "freebsd/FreeBSD-12.0-CURRENT", :vars => {} }
|
||||||
end
|
]
|
||||||
|
|
||||||
vms.each do |vm|
|
conts = [
|
||||||
config.vm.define vm[0] do |m|
|
{ :name => "docker-debian-jessie", :docker => "hanxhx/vagrant-ansible:debian8", :vars => { "nginx_php" => [{"version" => "5.6"}] }},
|
||||||
m.vm.box = vm[1]
|
{ :name => "docker-debian-jessie-backports", :docker => "hanxhx/vagrant-ansible:debian8", :vars => { "nginx_php": [{"version": "5.6"}], "nginx_backports": true }},
|
||||||
m.vm.network "private_network", ip: vm[2]
|
{ :name => "docker-debian-jessie-dotdeb", :docker => "hanxhx/vagrant-ansible:debian8", :vars => { "nginx_php": [{"version": "7.0"}, {"version": "5.6", "upstream_name": "legacy"} ], "dotdeb": true }},
|
||||||
|
{ :name => "docker-debian-stretch", :docker => "hanxhx/vagrant-ansible:debian9", :vars => { "nginx_php": [{"version": "7.0"}] }},
|
||||||
|
{ :name => "docker-debian-stretch-sury", :docker => "hanxhx/vagrant-ansible:debian9", :vars => { "nginx_php": [{"version": "7.1"}], "sury": true }}
|
||||||
|
]
|
||||||
|
|
||||||
|
config.vm.network "private_network", type: "dhcp"
|
||||||
|
config.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: true
|
||||||
|
|
||||||
|
conts.each do |opts|
|
||||||
|
config.vm.define opts[:name] do |m|
|
||||||
|
m.vm.provider "docker" do |d|
|
||||||
|
d.image = opts[:docker]
|
||||||
|
d.remains_running = true
|
||||||
|
d.has_ssh = true
|
||||||
|
end
|
||||||
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.become = true
|
||||||
|
ansible.extra_vars = opts[:vars].merge({ "nginx_debug_role": true })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
vms_debian.each do |opts|
|
||||||
|
config.vm.define opts[:name] do |m|
|
||||||
|
m.vm.box = opts[:box]
|
||||||
|
m.vm.provider "virtualbox" do |v|
|
||||||
|
v.cpus = 1
|
||||||
|
v.memory = 256
|
||||||
|
end
|
||||||
|
m.vm.provision "ansible" do |ansible|
|
||||||
|
ansible.playbook = "tests/test.yml"
|
||||||
|
ansible.verbose = 'vv'
|
||||||
|
ansible.become = true
|
||||||
|
ansible.extra_vars = opts[:vars].merge({ "nginx_debug_role": true })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
vms_freebsd.each do |opts|
|
||||||
|
config.vm.base_mac = "080027D14C66"
|
||||||
|
config.vm.define opts[:name] do |m|
|
||||||
|
m.vm.box = opts[:box]
|
||||||
|
m.vm.provider "virtualbox" do |v, override|
|
||||||
|
override.ssh.shell = "csh"
|
||||||
|
v.cpus = 2
|
||||||
|
v.memory = 512
|
||||||
|
end
|
||||||
|
m.vm.provision "shell", inline: "pkg install -y python bash"
|
||||||
|
m.vm.provision "ansible" do |ansible|
|
||||||
|
ansible.playbook = "tests/test.yml"
|
||||||
|
ansible.verbose = 'vv'
|
||||||
|
ansible.become = true
|
||||||
|
ansible.extra_vars = opts[:vars].merge({ "nginx_debug_role": true, "ansible_python_interpreter": '/usr/local/bin/python' })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,30 +1,38 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
|
# Debian
|
||||||
nginx_apt_package: nginx-full
|
nginx_apt_package: nginx-full
|
||||||
|
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_ssl_dir: '/etc/nginx/ssl'
|
nginx_resolver_hosts: ['8.8.8.8', '8.8.4.4']
|
||||||
nginx_pid: '/run/nginx.pid'
|
nginx_resolver_valid: '300s'
|
||||||
nginx_resolver:
|
nginx_resolver_timeout: '5s'
|
||||||
hosts: ['8.8.8.8', '8.8.4.4'] # OpenDNS
|
|
||||||
valid: '300'
|
|
||||||
timeout: '5'
|
|
||||||
nginx_error_log_level: 'warn' # http://nginx.org/en/docs/ngx_core_module.html#error_log
|
nginx_error_log_level: 'warn' # http://nginx.org/en/docs/ngx_core_module.html#error_log
|
||||||
nginx_dh_length: 2048
|
nginx_auto_config_httpv2: true
|
||||||
|
nginx_default_site: null
|
||||||
|
nginx_default_site_ssl: null
|
||||||
|
nginx_fastcgi_fix_realpath: true
|
||||||
|
|
||||||
|
#
|
||||||
|
# Nginx directories
|
||||||
|
#
|
||||||
|
nginx_htpasswd_dir: '{{ nginx_etc_dir }}/htpasswd'
|
||||||
|
nginx_ssl_dir: '{{ nginx_etc_dir }}/ssl'
|
||||||
|
nginx_helper_dir: '{{ nginx_etc_dir}}/helper'
|
||||||
|
|
||||||
#
|
#
|
||||||
# Load upstream
|
# Load upstream
|
||||||
#
|
#
|
||||||
|
|
||||||
# PHP
|
# PHP
|
||||||
nginx_php: false
|
nginx_php: []
|
||||||
nginx_php_sockets:
|
|
||||||
- unix_socket: "/var/run/php5-fpm.sock"
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Nginx configuration
|
# Nginx configuration
|
||||||
@@ -32,43 +40,92 @@ nginx_php_sockets:
|
|||||||
nginx_user: 'www-data'
|
nginx_user: 'www-data'
|
||||||
nginx_worker_processes: '{{ ansible_processor_vcpus }}'
|
nginx_worker_processes: '{{ ansible_processor_vcpus }}'
|
||||||
|
|
||||||
nginx_events:
|
#
|
||||||
worker_connections: '512'
|
# Nginx events
|
||||||
multi_accept: 'on'
|
#
|
||||||
use: 'epoll'
|
nginx_events_worker_connections: '512'
|
||||||
|
nginx_events_multi_accept: 'on'
|
||||||
|
|
||||||
#
|
#
|
||||||
# Nginx HTTP
|
# Nginx HTTP
|
||||||
#
|
#
|
||||||
nginx_http:
|
nginx_http_types_hash_max_size: 2048
|
||||||
access_log: 'off'
|
nginx_http_default_type: 'application/octet-stream'
|
||||||
error_log: 'off'
|
nginx_http_access_log: 'off'
|
||||||
client_body_buffer_size: '1M'
|
nginx_http_error_log: 'off'
|
||||||
client_header_buffer_size: '1M'
|
nginx_http_client_body_buffer_size: '1M'
|
||||||
client_max_body_size: '10M'
|
nginx_http_client_header_buffer_size: '1M'
|
||||||
large_client_header_buffers: '8 8k'
|
nginx_http_client_max_body_size: '10M'
|
||||||
client_body_timeout: '60'
|
nginx_http_large_client_header_buffers: '8 8k'
|
||||||
client_header_timeout: '60'
|
nginx_http_client_body_timeout: '60'
|
||||||
keepalive_timeout: '30 30'
|
nginx_http_client_header_timeout: '60'
|
||||||
send_timeout: '120'
|
nginx_http_keepalive_timeout: '30 30'
|
||||||
ignore_invalid_headers: 'on'
|
nginx_http_send_timeout: '120'
|
||||||
keepalive_requests: '100'
|
nginx_http_ignore_invalid_headers: 'on'
|
||||||
recursive_error_pages: 'on'
|
nginx_http_keepalive_requests: '100'
|
||||||
sendfile: 'on'
|
nginx_http_recursive_error_pages: 'on'
|
||||||
server_name_in_redirect: 'off'
|
nginx_http_sendfile: 'on'
|
||||||
server_tokens: 'off'
|
nginx_http_server_name_in_redirect: 'off'
|
||||||
tcp_nodelay: 'on'
|
nginx_http_server_tokens: 'off'
|
||||||
tcp_nopush: 'on'
|
nginx_http_tcp_nodelay: 'on'
|
||||||
reset_timedout_connection: 'on'
|
nginx_http_tcp_nopush: 'on'
|
||||||
gzip: 'on'
|
nginx_http_reset_timedout_connection: 'on'
|
||||||
gzip_buffers: '16 8k'
|
nginx_http_gzip: 'on'
|
||||||
gzip_comp_level: '9'
|
nginx_http_gzip_buffers: '16 8k'
|
||||||
gzip_http_version: '1.0'
|
nginx_http_gzip_comp_level: '9'
|
||||||
gzip_min_length: '0'
|
nginx_http_gzip_http_version: '1.0'
|
||||||
gzip_types: 'text/plain text/css application/json application/x-javascript application/javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml'
|
nginx_http_gzip_min_length: '0'
|
||||||
gzip_vary: 'on'
|
nginx_http_gzip_types: 'text/plain text/css application/json application/x-javascript application/javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml'
|
||||||
gzip_disable: '"msie6"'
|
nginx_http_gzip_vary: 'on'
|
||||||
# etag: 'off'
|
nginx_http_gzip_disable: '"msie6"'
|
||||||
|
|
||||||
nginx_vhosts: []
|
#
|
||||||
|
# Custom global configuration
|
||||||
|
#
|
||||||
|
nginx_custom_http: []
|
||||||
|
|
||||||
|
#
|
||||||
|
# Sites
|
||||||
|
#
|
||||||
|
nginx_sites: []
|
||||||
|
|
||||||
|
#
|
||||||
|
# Upstreams
|
||||||
|
#
|
||||||
nginx_upstreams: []
|
nginx_upstreams: []
|
||||||
|
|
||||||
|
#
|
||||||
|
# htpasswd
|
||||||
|
#
|
||||||
|
nginx_htpasswd: []
|
||||||
|
|
||||||
|
#
|
||||||
|
# SSL pairs
|
||||||
|
#
|
||||||
|
nginx_ssl_pairs: []
|
||||||
|
|
||||||
|
#
|
||||||
|
# Dynamic modules
|
||||||
|
#
|
||||||
|
nginx_module_packages: []
|
||||||
|
nginx_load_modules: []
|
||||||
|
|
||||||
|
#
|
||||||
|
# Diffie-Hellman
|
||||||
|
#
|
||||||
|
nginx_dh: null
|
||||||
|
nginx_dh_path: '{{ nginx_ssl_dir }}/dhparam.pem'
|
||||||
|
nginx_dh_length: 2048
|
||||||
|
|
||||||
|
#
|
||||||
|
# acme.sh
|
||||||
|
#
|
||||||
|
nginx_acmesh: false
|
||||||
|
nginx_acmesh_dir: "/opt/acme.sh"
|
||||||
|
nginx_acmesh_git_dir: "/tmp/acme.sh"
|
||||||
|
nginx_acmesh_test: false
|
||||||
|
|
||||||
|
#
|
||||||
|
# Debug
|
||||||
|
#
|
||||||
|
nginx_debug_role: false
|
||||||
|
|||||||
15
doc/acme.md
Normal file
15
doc/acme.md
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
acme.sh
|
||||||
|
=======
|
||||||
|
|
||||||
|
Notes
|
||||||
|
-----
|
||||||
|
|
||||||
|
This feature is experimental.
|
||||||
|
|
||||||
|
Variables
|
||||||
|
---------
|
||||||
|
|
||||||
|
- `nginx_acmesh`: (bool) Enable/Disable acme.sh feature
|
||||||
|
- `nginx_acmesh_dir`: (string) Install directory
|
||||||
|
- `nginx_acmesh_git_dir`: (string) Git directory (removed after install)
|
||||||
|
- `nginx_acmesh_test`: (bool) If set to true (default false), uses test mode
|
||||||
46
doc/auth.md
Normal file
46
doc/auth.md
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
Auth Basic management
|
||||||
|
=====================
|
||||||
|
|
||||||
|
IMPORTANT
|
||||||
|
---------
|
||||||
|
|
||||||
|
If you use this feature with Debian Stretch, you *MUST* use ansible >= 2.3.2! See: [https://github.com/HanXHX/ansible-nginx/issues/28](#28).
|
||||||
|
|
||||||
|
Description
|
||||||
|
-----------
|
||||||
|
|
||||||
|
Auth basic is managed in a separate list. Each auth file can be shared between locations or sites.
|
||||||
|
|
||||||
|
Each htpasswd has few keys:
|
||||||
|
|
||||||
|
- `name`: (M) used to create file and as pointee
|
||||||
|
- `description`: (M) Used for the message box :)
|
||||||
|
- `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
|
||||||
|
|
||||||
|
`nginx_htpasswd` should be placed in a vault file.
|
||||||
|
|
||||||
|
Example
|
||||||
|
-------
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
nginx_sites:
|
||||||
|
# htpasswd on all site
|
||||||
|
- name: test.local
|
||||||
|
htpasswd: 'hello'
|
||||||
|
template: '_base'
|
||||||
|
|
||||||
|
# htpasswd only in /hello
|
||||||
|
- name: test-location.local
|
||||||
|
template: '_base'
|
||||||
|
location:
|
||||||
|
'/hello':
|
||||||
|
- htpasswd: 'hello'
|
||||||
|
|
||||||
|
nginx_htpasswd:
|
||||||
|
- name: 'hello'
|
||||||
|
description: 'Please login!'
|
||||||
|
users:
|
||||||
|
- name: 'bob'
|
||||||
|
password: 'my_pass'
|
||||||
|
```
|
||||||
18
doc/freebsd.md
Normal file
18
doc/freebsd.md
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
Freebsd
|
||||||
|
=======
|
||||||
|
|
||||||
|
Limitations
|
||||||
|
-----------
|
||||||
|
|
||||||
|
Due to Ansible + FreeBSD limitations (`ansible_processor_vcpus`), You must explicitely set `nginx_worker_processes`.
|
||||||
|
|
||||||
|
About modules
|
||||||
|
-------------
|
||||||
|
|
||||||
|
Dynamic modules must be set with full path (see `nginx_load_modules` path).
|
||||||
|
|
||||||
|
Sites not tested
|
||||||
|
----------------
|
||||||
|
|
||||||
|
- BackupPC
|
||||||
|
- Nagios
|
||||||
23
doc/php.md
Normal file
23
doc/php.md
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
PHP
|
||||||
|
===
|
||||||
|
|
||||||
|
`nginx_php`:
|
||||||
|
- `version`: (M) PHP version
|
||||||
|
- `upstream_name` (O)
|
||||||
|
- `sockets`: (O) socket list
|
||||||
|
|
||||||
|
If `sockets` is not provided, if uses local unix socket (based on PHP version).
|
||||||
|
|
||||||
|
You should see [Nginx upstream module doc](http://nginx.org/en/docs/http/ngx_http_upstream_module.html).
|
||||||
|
|
||||||
|
Each socket have:
|
||||||
|
|
||||||
|
- `unix`
|
||||||
|
|
||||||
|
XOR
|
||||||
|
|
||||||
|
- `host`
|
||||||
|
- `port`
|
||||||
|
- `weight`
|
||||||
|
- `max_fails`
|
||||||
|
- `fail_timeout`
|
||||||
72
doc/site.md
Normal file
72
doc/site.md
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
Site management
|
||||||
|
===============
|
||||||
|
|
||||||
|
You can see many examples in: [tests/test.yml](../tests/test.yml).
|
||||||
|
|
||||||
|
`nginx_sites`: List of dict. A site has few keys. See bellow.
|
||||||
|
|
||||||
|
Common
|
||||||
|
------
|
||||||
|
|
||||||
|
- `name`: (M) Domain or list of domain used.
|
||||||
|
- `template`: (D) template used to create site. Optional if you set `state`=`absent` or using `redirect_to`.
|
||||||
|
- `filename`: (O) Specify filename in /etc/nginx/sites-*. Do NOT specify default (reserved keyword). It will be used for log filenames and directories creation.
|
||||||
|
- `state`: (O) Site status. Can be "present" (default), "absent" and "disabled".
|
||||||
|
- `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).
|
||||||
|
- `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_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_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.
|
||||||
|
- `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
|
||||||
|
- `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 site. Set "false" to disable.
|
||||||
|
- `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. 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".
|
||||||
|
- `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
|
||||||
|
(M): Mandatory
|
||||||
|
(D): Depends other keys...
|
||||||
|
|
||||||
|
Templates
|
||||||
|
---------
|
||||||
|
|
||||||
|
- `_base`: static template
|
||||||
|
- `_backuppc`: access to [BackupPC](http://backuppc.sourceforge.net/) (be careful: you need to install [fcgiwrap](https://packages.debian.org/jessie/fcgiwrap))
|
||||||
|
- `_dokuwiki`
|
||||||
|
- `_redirect`: should not be called explicitly
|
||||||
|
- `_nagios3`: access to Nagios3 (be careful: you need to install [fcgiwrap](https://packages.debian.org/jessie/fcgiwrap))
|
||||||
|
- `_phalcon`: Phalcon PHP Framework
|
||||||
|
- `_php`: PHP base template. Can work with many frameworks/tools
|
||||||
|
- `_php_index`: Same as above. But you can only run index.php
|
||||||
|
- `_proxy`
|
||||||
|
- `_wordpress`
|
||||||
|
|
||||||
|
Templates works as parent-child.
|
||||||
|
|
||||||
|
About proxy template
|
||||||
|
--------------------
|
||||||
|
|
||||||
|
Proxy template allow you to use Nginx as reverse proxy. Usefull when you have an application service such as Redmine, Jenkins...
|
||||||
|
|
||||||
|
You have many key added to site key:
|
||||||
|
|
||||||
|
- `upstream_name`: (O) upstream name used to pass proxy
|
||||||
|
- `proxy_params`: (M) list of raw params passed to the site
|
||||||
|
|
||||||
|
(O) : Optional
|
||||||
|
|
||||||
|
Default sites
|
||||||
|
--------------
|
||||||
|
|
||||||
|
You can manage default site by setting domain name to these variables.
|
||||||
|
|
||||||
|
- `nginx_default_site`
|
||||||
|
- `nginx_default_site_ssl`
|
||||||
72
doc/ssl.md
Normal file
72
doc/ssl.md
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
SSL/TLS Management
|
||||||
|
==================
|
||||||
|
|
||||||
|
You can put all this variables in a separated vault file.
|
||||||
|
|
||||||
|
Variables
|
||||||
|
---------
|
||||||
|
|
||||||
|
- `nginx_dh`: DH content
|
||||||
|
- `nginx_dh_length`: DH key length (default is 2048)
|
||||||
|
- `nginx_dh_path`: file localation
|
||||||
|
- `nginx_ssl_dir`: directory where you install your SSL/TLS keys
|
||||||
|
- `nginx_ssl_pairs`
|
||||||
|
|
||||||
|
Cert/Key pairs
|
||||||
|
--------------
|
||||||
|
|
||||||
|
This list have 3 mandatory keys:
|
||||||
|
|
||||||
|
- `name`: MUST be unique
|
||||||
|
|
||||||
|
- `key`: content of the private key
|
||||||
|
- `cert`: content of the public key
|
||||||
|
|
||||||
|
OR
|
||||||
|
|
||||||
|
- `dest_cert`: remote path where certificate 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
|
||||||
|
|
||||||
|
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`!
|
||||||
|
- In `nginx_sites`, `ssl_name` is mandatory. This role will search in `nginx_ssl_pairs` with site `name` (first in list if it's a list).
|
||||||
|
|
||||||
|
Diffie-Hellman
|
||||||
|
--------------
|
||||||
|
|
||||||
|
If you do not specify any dh param, this role auto generates it.
|
||||||
|
|
||||||
|
Example
|
||||||
|
-------
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
nginx_sites;
|
||||||
|
- name: 'test-ssl.local'
|
||||||
|
proto: ['http', 'https']
|
||||||
|
template: '_base'
|
||||||
|
ssl_name: 'mysuperkey'
|
||||||
|
- name: 'test-ssl2.local'
|
||||||
|
proto: ['http', 'https']
|
||||||
|
template: '_base'
|
||||||
|
- name: 'test-ssl3.local'
|
||||||
|
proto: ['http', 'https']
|
||||||
|
template: '_base'
|
||||||
|
|
||||||
|
nginx_ssl_pairs:
|
||||||
|
- name: mysuperkey
|
||||||
|
key: |
|
||||||
|
-----BEGIN RSA PRIVATE KEY-----
|
||||||
|
....(snip)....
|
||||||
|
-----END RSA PRIVATE KEY-----
|
||||||
|
cert: |
|
||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
....(snip)....
|
||||||
|
-----END CERTIFICATE-----
|
||||||
|
- name: test-ssl2.local
|
||||||
|
acme: true
|
||||||
|
```
|
||||||
|
|
||||||
43
doc/upstream.md
Normal file
43
doc/upstream.md
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
Upstream management
|
||||||
|
===================
|
||||||
|
|
||||||
|
`nginx_upstreams`: List of dict. An upstream has few keys. See bellow.
|
||||||
|
|
||||||
|
Note: Few params are unavailable on old Nginx version. But this role do _not_ put it if your version is too old!
|
||||||
|
|
||||||
|
Upstream params
|
||||||
|
---------------
|
||||||
|
|
||||||
|
- `name`: upstream name. Can be use in site with *proxy_pass http://upstream_name*
|
||||||
|
- `params`: list of param (hash, zone...)
|
||||||
|
- `servers`: each upstream MUST have at least 1 server
|
||||||
|
- `state`: Optional. Can be 'absent' or 'present'
|
||||||
|
|
||||||
|
Server params
|
||||||
|
-------------
|
||||||
|
|
||||||
|
You must set a `path`. For example: *192.168.0.50:8080* or *unix:/tmp/my.sock*.
|
||||||
|
|
||||||
|
All this params are optional. You should see [Nginx upstream doc](http://nginx.org/en/docs/http/ngx_http_upstream_module.html).
|
||||||
|
|
||||||
|
- `weight`
|
||||||
|
- `max_fails`
|
||||||
|
- `fail_timeout`
|
||||||
|
- `backup`
|
||||||
|
- `down`
|
||||||
|
- `route`
|
||||||
|
- `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'
|
||||||
|
```
|
||||||
@@ -1 +0,0 @@
|
|||||||
<h1>HTML works</h1>
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
echo "<h1>PHP works!</h1>";
|
|
||||||
20
filter_plugins/nginx.py
Normal file
20
filter_plugins/nginx.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
def nginx_site_filename(site):
|
||||||
|
if site.has_key('filename'):
|
||||||
|
return site['filename']
|
||||||
|
else:
|
||||||
|
return nginx_site_name(site)
|
||||||
|
|
||||||
|
def nginx_site_name(site):
|
||||||
|
if isinstance(site['name'], list):
|
||||||
|
return site['name'][0]
|
||||||
|
else:
|
||||||
|
return site['name']
|
||||||
|
|
||||||
|
class FilterModule(object):
|
||||||
|
''' Nginx module '''
|
||||||
|
|
||||||
|
def filters(self):
|
||||||
|
return {
|
||||||
|
'nginx_site_filename': nginx_site_filename,
|
||||||
|
'nginx_site_name': nginx_site_name
|
||||||
|
}
|
||||||
25
filter_plugins/php.py
Normal file
25
filter_plugins/php.py
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
def php_default_upstream_socket(php_version):
|
||||||
|
if php_version == '5.6':
|
||||||
|
return '/run/php5-fpm.sock'
|
||||||
|
else:
|
||||||
|
return '/run/php/php%s-fpm.sock' % php_version
|
||||||
|
|
||||||
|
def php_default_upstream_name(php_version):
|
||||||
|
return 'default_php_%s' % php_version
|
||||||
|
|
||||||
|
def php_fpm_service(php_version):
|
||||||
|
if php_version == '5.6':
|
||||||
|
return 'php5-fpm'
|
||||||
|
else:
|
||||||
|
return 'php%s-fpm' % php_version
|
||||||
|
|
||||||
|
class FilterModule(object):
|
||||||
|
''' PHP module '''
|
||||||
|
|
||||||
|
def filters(self):
|
||||||
|
return {
|
||||||
|
'php_default_upstream_socket': php_default_upstream_socket,
|
||||||
|
'php_default_upstream_name': php_default_upstream_name,
|
||||||
|
'php_fpm_service': php_fpm_service,
|
||||||
|
'php_fpm_package': php_fpm_service
|
||||||
|
}
|
||||||
@@ -1,4 +1,42 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
- name: reload nginx
|
- name: reload nginx
|
||||||
action: service name=nginx state=reloaded enabled=yes
|
command: nginx -t
|
||||||
|
notify:
|
||||||
|
- real-reload nginx
|
||||||
|
- docker reload nginx
|
||||||
|
|
||||||
|
- name: restart nginx
|
||||||
|
command: nginx -t
|
||||||
|
notify:
|
||||||
|
- real-restart nginx
|
||||||
|
- docker restart nginx
|
||||||
|
|
||||||
|
- name: real-reload nginx
|
||||||
|
service:
|
||||||
|
name: nginx
|
||||||
|
state: reloaded
|
||||||
|
when: ansible_virtualization_type != 'docker'
|
||||||
|
|
||||||
|
- name: real-restart nginx
|
||||||
|
service:
|
||||||
|
name: nginx
|
||||||
|
state: restarted
|
||||||
|
when: ansible_virtualization_type != 'docker'
|
||||||
|
|
||||||
|
- name: docker reload nginx
|
||||||
|
command: service nginx reload
|
||||||
|
when: ansible_virtualization_type == 'docker'
|
||||||
|
|
||||||
|
- name: docker restart nginx
|
||||||
|
command: service nginx restart
|
||||||
|
when: ansible_virtualization_type == 'docker'
|
||||||
|
|
||||||
|
- name: restart nginx freebsd
|
||||||
|
service:
|
||||||
|
name: nginx
|
||||||
|
state: restarted
|
||||||
|
when: ansible_distribution == "FreeBSD"
|
||||||
|
|
||||||
|
- name: setup
|
||||||
|
action: setup
|
||||||
|
|||||||
@@ -1,16 +1,26 @@
|
|||||||
---
|
---
|
||||||
galaxy_info:
|
galaxy_info:
|
||||||
author: Emilien Mantel
|
author: Emilien Mantel
|
||||||
description: Nginx for Debian
|
description: Nginx for Debian
|
||||||
company:
|
company:
|
||||||
license: GPLv2
|
license: GPLv2
|
||||||
min_ansible_version: 1.6
|
min_ansible_version: 2.2
|
||||||
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: []
|
||||||
|
|
||||||
|
|||||||
44
tasks/config.yml
Normal file
44
tasks/config.yml
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
- name: TEMPLATE | Deploy nginx.conf
|
||||||
|
template:
|
||||||
|
src: "etc/nginx/nginx.conf.j2"
|
||||||
|
dest: "{{ nginx_etc_dir }}/nginx.conf"
|
||||||
|
notify: reload nginx
|
||||||
|
|
||||||
|
- name: TEMPLATE | Deploy all helpers
|
||||||
|
template:
|
||||||
|
src: "{{ item }}"
|
||||||
|
dest: "{{ nginx_helper_dir }}/{{ item | basename | regex_replace('.j2$','') }}"
|
||||||
|
with_fileglob: '../templates/etc/nginx/helper/*.j2'
|
||||||
|
notify: reload nginx
|
||||||
|
|
||||||
|
- name: TEMPLATE | Deploy custom http configuration
|
||||||
|
template:
|
||||||
|
src: "etc/nginx/conf.d/custom.conf.j2"
|
||||||
|
dest: "{{ nginx_etc_dir }}/conf.d/custom.conf"
|
||||||
|
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;'
|
||||||
|
-
|
||||||
|
- '{{ nginx_etc_dir }}/fastcgi.conf'
|
||||||
|
when: nginx_fastcgi_fix_realpath
|
||||||
|
|
||||||
|
- name: COPY | Add modules manually
|
||||||
|
copy:
|
||||||
|
content: |
|
||||||
|
{% for m in nginx_load_modules %}
|
||||||
|
load_module {{ m }};
|
||||||
|
{% endfor %}
|
||||||
|
dest: "{{ nginx_etc_dir }}/modules-enabled/000-modules.conf"
|
||||||
|
notify: reload nginx
|
||||||
21
tasks/htpasswd.yml
Normal file
21
tasks/htpasswd.yml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
- name: FILE | Delete htpasswd file
|
||||||
|
file:
|
||||||
|
path: "{{ nginx_htpasswd_dir }}/{{ item.name }}"
|
||||||
|
state: absent
|
||||||
|
with_items: "{{ nginx_htpasswd }}"
|
||||||
|
when: item.state is defined and item.state == 'absent'
|
||||||
|
no_log: not nginx_debug_role
|
||||||
|
|
||||||
|
- name: HTPASSWD | Manage files
|
||||||
|
htpasswd:
|
||||||
|
name: "{{ item.1.name }}"
|
||||||
|
password: "{{ item.1.password }}"
|
||||||
|
state: "{{ item.1.state | default('present') }}"
|
||||||
|
path: "{{ nginx_htpasswd_dir }}/{{ item.0.name }}"
|
||||||
|
with_subelements:
|
||||||
|
- "{{ nginx_htpasswd }}"
|
||||||
|
- users
|
||||||
|
when: item.0.state is not defined or item.0.state == 'present'
|
||||||
|
no_log: not nginx_debug_role
|
||||||
67
tasks/install_Debian.yml
Normal file
67
tasks/install_Debian.yml
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
- name: FAIL | Check possible issues
|
||||||
|
fail:
|
||||||
|
msg: "This ansible version ({{ ansible_version.full}}) is not compatible with your needs (Debian Stretch + htpasswd). Please see https://github.com/HanXHX/ansible-nginx/issues/28"
|
||||||
|
when:
|
||||||
|
ansible_distribution_major_version | version_compare('9', 'ge') and
|
||||||
|
ansible_version.full | version_compare('2.3.2', 'lt') and
|
||||||
|
nginx_htpasswd | length > 0
|
||||||
|
|
||||||
|
- name: APT | Update cache
|
||||||
|
apt:
|
||||||
|
update_cache: yes
|
||||||
|
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
|
||||||
|
apt:
|
||||||
|
pkg: "{{ nginx_apt_package }}"
|
||||||
|
state: present
|
||||||
|
default_release: "{{ ansible_distribution_release + '-backports' if nginx_backports else ansible_distribution_release }}"
|
||||||
|
|
||||||
|
- name: APT | Install nginx modules
|
||||||
|
apt:
|
||||||
|
pkg: "{{ item }}"
|
||||||
|
state: present
|
||||||
|
with_items: "{{ nginx_module_packages }}"
|
||||||
|
when:
|
||||||
|
ansible_distribution_major_version | version_compare('9', 'ge') or
|
||||||
|
nginx_backports
|
||||||
|
|
||||||
|
- name: APT | Install python-passlib
|
||||||
|
apt:
|
||||||
|
pkg: python-passlib
|
||||||
|
state: present
|
||||||
|
|
||||||
|
- name: STAT | Check acme.sh is installed
|
||||||
|
stat:
|
||||||
|
path: "{{ nginx_acmesh_dir }}"
|
||||||
|
register: acme
|
||||||
|
|
||||||
|
- block:
|
||||||
|
|
||||||
|
- name: APT | Install git
|
||||||
|
apt:
|
||||||
|
pkg: git
|
||||||
|
|
||||||
|
- name: GIT | Get acme.sh
|
||||||
|
git:
|
||||||
|
repo: 'https://github.com/Neilpang/acme.sh.git'
|
||||||
|
dest: '{{ nginx_acmesh_git_dir }}'
|
||||||
|
update: no
|
||||||
|
|
||||||
|
- name: SHELL | Install acme.sh
|
||||||
|
shell: ./acme.sh --install --home {{ nginx_acmesh_dir }} --cert-home {{ nginx_acmesh_dir }}
|
||||||
|
args:
|
||||||
|
chdir: "{{ nginx_acmesh_git_dir }}"
|
||||||
|
creates: "{{ nginx_acmesh_dir }}"
|
||||||
|
|
||||||
|
when: not acme.stat.exists
|
||||||
59
tasks/install_FreeBSD.yml
Normal file
59
tasks/install_FreeBSD.yml
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
- name: PKGNG | Install nginx and related tools
|
||||||
|
pkgng:
|
||||||
|
name: "{{ item }}"
|
||||||
|
state: present
|
||||||
|
with_items:
|
||||||
|
- acme.sh
|
||||||
|
- "{{ nginx_pkgng_package }}"
|
||||||
|
- py27-passlib
|
||||||
|
- curl
|
||||||
|
|
||||||
|
#
|
||||||
|
# Bypass https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=224166#c1
|
||||||
|
#
|
||||||
|
- block:
|
||||||
|
|
||||||
|
- name: COMMAND | Create /usr/local/etc/fdfs/http.conf
|
||||||
|
command: touch /usr/local/etc/fdfs/http.conf
|
||||||
|
args:
|
||||||
|
creates: /usr/local/etc/fdfs/http.conf
|
||||||
|
register: fd1
|
||||||
|
|
||||||
|
- name: LINEINFILE | Tune fdfs
|
||||||
|
lineinfile:
|
||||||
|
regexp: ^load_fdfs_parameters_from_tracker
|
||||||
|
line: load_fdfs_parameters_from_tracker=false
|
||||||
|
path: /usr/local/etc/fdfs/mod_fastdfs.conf
|
||||||
|
register: fd2
|
||||||
|
|
||||||
|
- name: SERVICE | Restart nginx when fdfs is tuned
|
||||||
|
service:
|
||||||
|
name: nginx
|
||||||
|
state: restarted
|
||||||
|
when: fd1.changed or fd2.changed
|
||||||
|
|
||||||
|
when: true
|
||||||
|
|
||||||
|
- name: FILE | Create configuration dir (like Debian)
|
||||||
|
file:
|
||||||
|
path: "{{ nginx_etc_dir }}/{{ item }}"
|
||||||
|
state: directory
|
||||||
|
with_items:
|
||||||
|
- conf.d
|
||||||
|
- sites-available
|
||||||
|
- sites-enabled
|
||||||
|
|
||||||
|
- 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,44 +1,30 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
- name: APT | Install nginx
|
- name: INCLUDE_VARS | Related to OS
|
||||||
apt: pkg={{ nginx_apt_package }} state=latest update_cache=yes cache_valid_time=3600
|
include_vars: "{{ ansible_distribution }}.yml"
|
||||||
|
tags: ['nginx::site', 'nginx::ssl']
|
||||||
|
|
||||||
- name: SHELL | Get Nginx version
|
- name: INCLUDE | Install
|
||||||
shell: nginx -v 2>&1 | sed -r 's#.*/##;' | cut -d ' ' -f 1
|
include: "install_{{ ansible_distribution }}.yml"
|
||||||
register: nginx_version
|
tags: ['nginx::site', 'nginx::ssl']
|
||||||
changed_when: false
|
|
||||||
|
|
||||||
- name: TEMPLATE | Deploy nginx.conf
|
- name: INCLUDE | Prepare
|
||||||
template: >
|
include: prepare.yml
|
||||||
src=etc/nginx/nginx.conf.j2
|
tags: ['nginx::site', 'nginx::ssl']
|
||||||
dest=/etc/nginx/nginx.conf
|
|
||||||
notify: reload nginx
|
|
||||||
|
|
||||||
- name: FILE | Create /etc/nginx/helpers
|
- name: INCLUDE | Install
|
||||||
file: dest=/etc/nginx/helpers owner=root mode=0755 state=directory
|
include: config.yml
|
||||||
|
|
||||||
- name: FILE | Create /etc/nginx/ssl
|
|
||||||
file: dest=/etc/nginx/ssl owner=root mode=0755 state=directory
|
|
||||||
|
|
||||||
#- name: COMMAND | Creates DH file
|
|
||||||
# command: openssl dhparam -out {{ nginx_dh_path }} {{ nginx_dh_length }}
|
|
||||||
# args:
|
|
||||||
# creates: "{{ nginx_dh_path }}"
|
|
||||||
|
|
||||||
- name: TEMPLATE | Deploy all helpers
|
|
||||||
template: >
|
|
||||||
src={{ item }}
|
|
||||||
dest=/etc/nginx/helpers/{{ item | basename | regex_replace('\.j2$','') }}
|
|
||||||
with_fileglob: '../templates/etc/nginx/helpers/*.j2'
|
|
||||||
notify: reload nginx
|
|
||||||
|
|
||||||
- name: INCLUDE | Upstream configuration
|
- name: INCLUDE | Upstream configuration
|
||||||
include: upstream.yml
|
include: upstream.yml
|
||||||
when: nginx_php
|
|
||||||
|
|
||||||
- name: INCLUDE | Vhosts configuration
|
- name: INCLUDE | htpasswd configuration
|
||||||
include: vhost.yml
|
include: htpasswd.yml
|
||||||
|
|
||||||
# TODO:
|
- name: INCLUDE | SSL configuration
|
||||||
# - Python
|
include: ssl/main.yml
|
||||||
# - Ruby (SHIT!)
|
tags: ['nginx::ssl']
|
||||||
|
|
||||||
|
- name: INCLUDE | Sites configuration
|
||||||
|
include: site.yml
|
||||||
|
tags: ['nginx::site']
|
||||||
|
|||||||
34
tasks/prepare.yml
Normal file
34
tasks/prepare.yml
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
- name: SHELL | Get Nginx version
|
||||||
|
shell: nginx -v 2>&1 | sed -r 's#.*/##;' | cut -d ' ' -f 1
|
||||||
|
args:
|
||||||
|
executable: /bin/sh
|
||||||
|
register: nginx_version
|
||||||
|
changed_when: false
|
||||||
|
check_mode: no
|
||||||
|
|
||||||
|
- name: SHELL | Get module list
|
||||||
|
shell: nginx -V 2>&1 | tr -- - '\n' | grep -A 1 with | grep _module | sed -r 's/_module//g; s/\s+//g' | sort
|
||||||
|
args:
|
||||||
|
executable: /bin/sh
|
||||||
|
register: shell_modules
|
||||||
|
changed_when: false
|
||||||
|
check_mode: no
|
||||||
|
|
||||||
|
- name: SET_FACT | Save modules
|
||||||
|
set_fact:
|
||||||
|
nginx_modules: "{{ shell_modules.stdout_lines }}"
|
||||||
|
|
||||||
|
- name: FILE | Create folders
|
||||||
|
file:
|
||||||
|
dest: "{{ item.dir }}"
|
||||||
|
owner: "{{ item.owner }}"
|
||||||
|
mode: "{{ item.mode }}"
|
||||||
|
state: directory
|
||||||
|
with_items: "{{ nginx_dirs }}"
|
||||||
|
|
||||||
|
- name: FILE | Create ansible facts dir
|
||||||
|
file:
|
||||||
|
path: /etc/ansible/facts.d
|
||||||
|
state: directory
|
||||||
106
tasks/site.yml
Normal file
106
tasks/site.yml
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
- name: FAIL | Check filenames
|
||||||
|
fail:
|
||||||
|
msg: "Forbidden keyword default on site {{ item | nginx_site_name }}"
|
||||||
|
when: item.filename is defined and item.filename == 'default'
|
||||||
|
with_items: "{{ nginx_sites }}"
|
||||||
|
loop_control:
|
||||||
|
label: "{{ item | nginx_site_name }}"
|
||||||
|
|
||||||
|
- 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_sites }}"
|
||||||
|
loop_control:
|
||||||
|
label: "{{ item | nginx_site_name }}"
|
||||||
|
|
||||||
|
- name: FILE | Create root directory
|
||||||
|
file:
|
||||||
|
path: "{{ nginx_root }}"
|
||||||
|
state: directory
|
||||||
|
|
||||||
|
- name: FILE | Create root public folders (foreach nginx_sites)
|
||||||
|
file:
|
||||||
|
path: "{{ nginx_root }}/{{ item | nginx_site_filename }}/public"
|
||||||
|
state: directory
|
||||||
|
owner: "{{ item.owner | default(nginx_user) }}"
|
||||||
|
group: "{{ item.group | default(nginx_user) }}"
|
||||||
|
mode: "{{ item.mode | default('0755') }}"
|
||||||
|
with_items: "{{ nginx_sites }}"
|
||||||
|
when: >
|
||||||
|
item.root is not defined and
|
||||||
|
(item.template is defined and item.template not in nginx_templates_no_dir) and
|
||||||
|
(item.state is not defined or not item.state != 'absent') and
|
||||||
|
item.redirect_to is not defined
|
||||||
|
loop_control:
|
||||||
|
label: "{{ item | nginx_site_name }}"
|
||||||
|
|
||||||
|
- name: TEMPLATE | Create sites
|
||||||
|
template:
|
||||||
|
src: "etc/nginx/sites-available/{{ item.template if item.redirect_to is not defined else '_redirect' }}.j2"
|
||||||
|
dest: "{{ nginx_etc_dir }}/sites-available/{{ item | nginx_site_filename }}"
|
||||||
|
with_items: "{{ nginx_sites }}"
|
||||||
|
notify: ['reload nginx', 'restart nginx freebsd']
|
||||||
|
when: item.state is not defined or item.state != 'absent'
|
||||||
|
loop_control:
|
||||||
|
label: "{{ item | nginx_site_name }}"
|
||||||
|
|
||||||
|
- name: FILE | Delete sites
|
||||||
|
file:
|
||||||
|
path: "{{ nginx_etc_dir }}/{{ item.1 }}/{{ item.0 | nginx_site_filename }}"
|
||||||
|
state: absent
|
||||||
|
with_nested:
|
||||||
|
- "{{ nginx_sites }}"
|
||||||
|
- ['sites-available', 'sites-enabled']
|
||||||
|
notify: ['reload nginx', 'restart nginx freebsd']
|
||||||
|
when: item.0.state is defined and item.0.state == 'absent'
|
||||||
|
loop_control:
|
||||||
|
label: "{{ nginx_etc_dir }}/{{ item.1 }}/{{ item.0 | nginx_site_filename }}"
|
||||||
|
|
||||||
|
- name: FILE | Enable sites
|
||||||
|
file:
|
||||||
|
src: "{{ nginx_etc_dir }}/sites-available/{{ item | nginx_site_filename }}"
|
||||||
|
dest: "{{ nginx_etc_dir }}/sites-enabled/{{ item | nginx_site_filename }}"
|
||||||
|
state: link
|
||||||
|
with_items: "{{ nginx_sites }}"
|
||||||
|
notify: ['reload nginx', 'restart nginx freebsd']
|
||||||
|
when: >
|
||||||
|
item.state is not defined or item.state == 'present'
|
||||||
|
loop_control:
|
||||||
|
label: "{{ item | nginx_site_name }}"
|
||||||
|
|
||||||
|
- name: FILE | Disable sites
|
||||||
|
file:
|
||||||
|
path: "{{ nginx_etc_dir}}/sites-enabled/{{ item | nginx_site_filename }}"
|
||||||
|
state: absent
|
||||||
|
with_items: "{{ nginx_sites }}"
|
||||||
|
notify: ['reload nginx', 'restart nginx freebsd']
|
||||||
|
when: item.state is defined and item.state == 'disabled'
|
||||||
|
loop_control:
|
||||||
|
label: "{{ item | nginx_site_name }}"
|
||||||
|
|
||||||
|
- name: FILE | Delete default site when explicitely defined
|
||||||
|
file:
|
||||||
|
path: "{{ nginx_etc_dir }}/sites-enabled/default"
|
||||||
|
state: absent
|
||||||
|
notify: ['reload nginx', 'restart nginx freebsd']
|
||||||
|
when: nginx_default_site is not none
|
||||||
|
|
||||||
|
- name: FILE | Auto set default site
|
||||||
|
file:
|
||||||
|
src: "{{ nginx_etc_dir }}/sites-available/default"
|
||||||
|
dest: "{{ nginx_etc_dir }}/sites-enabled/default"
|
||||||
|
state: link
|
||||||
|
notify: ['reload nginx', 'restart nginx freebsd']
|
||||||
|
when: nginx_default_site is none
|
||||||
|
|
||||||
|
- name: TEMPLATE | Deploy facts
|
||||||
|
template:
|
||||||
|
src: etc/ansible/facts.d/nginx.fact.j2
|
||||||
|
dest: /etc/ansible/facts.d/nginx.fact
|
||||||
|
mode: 0644
|
||||||
|
notify: ['setup']
|
||||||
63
tasks/ssl/acme.yml
Normal file
63
tasks/ssl/acme.yml
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
- name: SET_FACT | Assign default..
|
||||||
|
set_fact:
|
||||||
|
acme_create: []
|
||||||
|
|
||||||
|
- name: STAT | Check if certificates are already installed
|
||||||
|
stat:
|
||||||
|
path: "{{ nginx_ssl_dir }}/{{ item | nginx_site_name }}/{{ item | nginx_site_name }}.crt"
|
||||||
|
with_items: "{{ nginx_ssl_pairs }}"
|
||||||
|
when: item.acme is defined and item.acme
|
||||||
|
register: acme_installed_certs
|
||||||
|
|
||||||
|
- name: SET_FACT | Assign var with certificates to create
|
||||||
|
set_fact:
|
||||||
|
acme_create: "{{ acme_create | default([]) + [ (item.item | combine({'listen': ([item.item.acme_port|default(80)]) }) ) ] }}"
|
||||||
|
with_items: "{{ acme_installed_certs.results }}"
|
||||||
|
when: item.skipped is not defined and not item.stat.exists
|
||||||
|
|
||||||
|
- name: TEMPLATE | Create fake site
|
||||||
|
template:
|
||||||
|
src: "etc/nginx/sites-available/_base.j2"
|
||||||
|
dest: "{{ nginx_etc_dir }}/conf.d/FAKESITE_{{ item | nginx_site_name }}.conf"
|
||||||
|
with_items: "{{ acme_create }}"
|
||||||
|
register: fake_site
|
||||||
|
|
||||||
|
- name: SERVICE | Restart nginx
|
||||||
|
service:
|
||||||
|
name: nginx
|
||||||
|
state: restarted
|
||||||
|
when: fake_site.changed and ansible_virtualization_type != 'docker'
|
||||||
|
|
||||||
|
- name: COMMAND | Restart nginx
|
||||||
|
command: service nginx restart
|
||||||
|
when: fake_site.changed and ansible_virtualization_type == 'docker'
|
||||||
|
|
||||||
|
- name: SHELL | Get certificates
|
||||||
|
shell: '{{ nginx_acmesh_bin }} --issue{% if item.name is string %} -d {{ item.name }}{% else %}{% for name in item.name %} -d {{ name }}{% endfor %}{% endif %} --nginx {% if nginx_acmesh_test %}--test{% endif %}'
|
||||||
|
args:
|
||||||
|
creates: "/root/.acme.sh/{{ item | nginx_site_name }}/{{ item | nginx_site_name }}.key"
|
||||||
|
with_items: "{{ acme_create }}"
|
||||||
|
register: acme_get
|
||||||
|
failed_when: acme_get.rc != 0 and acme_get.rc != 2
|
||||||
|
no_log: not nginx_debug_role
|
||||||
|
|
||||||
|
- name: FILE | Create SSL dir per site
|
||||||
|
file:
|
||||||
|
path: "{{ nginx_ssl_dir }}/{{ item | nginx_site_name }}"
|
||||||
|
with_items: "{{ acme_create }}"
|
||||||
|
|
||||||
|
- name: SHELL | Install certificates
|
||||||
|
shell: '{{ nginx_acmesh_bin }} --install-cert -d {{ item | nginx_site_name }} --fullchain-file {{ nginx_ssl_dir }}/{{ item | nginx_site_name }}/{{ item | nginx_site_name }}.crt --key-file {{ nginx_ssl_dir }}/{{ item | nginx_site_name }}/{{ item | nginx_site_name }}.key'
|
||||||
|
args:
|
||||||
|
creates: "{{ nginx_ssl_dir }}/{{ item | nginx_site_name }}/{{ item | nginx_site_name }}.key"
|
||||||
|
with_items: "{{ nginx_ssl_pairs }}"
|
||||||
|
when: item.acme is defined and item.acme
|
||||||
|
notify: restart nginx
|
||||||
|
|
||||||
|
- name: FILE | Delete fake sites
|
||||||
|
file:
|
||||||
|
path: "{{ nginx_etc_dir }}/conf.d/FAKESITE_{{ item | nginx_site_name }}.conf"
|
||||||
|
state: absent
|
||||||
|
with_items: "{{ acme_create }}"
|
||||||
8
tasks/ssl/main.yml
Normal file
8
tasks/ssl/main.yml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
- name: INCLUDE | standard.yml
|
||||||
|
include: standard.yml
|
||||||
|
|
||||||
|
- name: INCLUDE | acme.yml
|
||||||
|
include: acme.yml
|
||||||
|
when: nginx_acmesh
|
||||||
53
tasks/ssl/standard.yml
Normal file
53
tasks/ssl/standard.yml
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
- name: COMMAND | Generate DH file
|
||||||
|
command: openssl dhparam -out {{ nginx_dh_path }} {{ nginx_dh_length }}
|
||||||
|
args:
|
||||||
|
creates: "{{ nginx_dh_path }}"
|
||||||
|
when: nginx_dh is not string
|
||||||
|
notify: restart nginx
|
||||||
|
async: 1000
|
||||||
|
register: dh
|
||||||
|
|
||||||
|
- name: COPY | Deploy DH file from vars
|
||||||
|
copy:
|
||||||
|
content: "{{ nginx_dh }}"
|
||||||
|
dest: "{{ nginx_dh_path }}"
|
||||||
|
when: nginx_dh is string
|
||||||
|
notify: restart nginx
|
||||||
|
|
||||||
|
- name: FILE | Create SSL directories
|
||||||
|
file:
|
||||||
|
path: "{{ nginx_ssl_dir + '/' + item.name }}"
|
||||||
|
state: directory
|
||||||
|
with_items: "{{ nginx_ssl_pairs }}"
|
||||||
|
when: item.dest_key is not defined or item.dest_cert is not defined
|
||||||
|
no_log: not nginx_debug_role
|
||||||
|
|
||||||
|
- name: COPY | Deploy SSL keys
|
||||||
|
copy:
|
||||||
|
content: "{{ item.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 }}"
|
||||||
|
when: item.key is defined
|
||||||
|
notify: restart nginx
|
||||||
|
no_log: not nginx_debug_role
|
||||||
|
|
||||||
|
- name: COPY | Deploy SSL certs
|
||||||
|
copy:
|
||||||
|
content: "{{ item.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 }}"
|
||||||
|
when: item.cert is defined
|
||||||
|
notify: restart nginx
|
||||||
|
no_log: not nginx_debug_role
|
||||||
|
|
||||||
|
- name: Check DH command status
|
||||||
|
async_status:
|
||||||
|
jid: "{{ dh.ansible_job_id }}"
|
||||||
|
register: job_result
|
||||||
|
until: job_result.finished
|
||||||
|
retries: 30
|
||||||
|
when: not ansible_check_mode and nginx_dh is not string
|
||||||
@@ -1,10 +1,30 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
- 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:
|
||||||
|
src: "etc/nginx/conf.d/php.conf.j2"
|
||||||
|
dest: "{{ nginx_etc_dir }}/conf.d/php.conf"
|
||||||
|
when: nginx_php | length > 0
|
||||||
notify: reload nginx
|
notify: reload nginx
|
||||||
|
|
||||||
|
- name: FILE | Delete PHP upstream
|
||||||
|
file:
|
||||||
|
path: "{{ nginx_etc_dir }}/conf.d/php.conf"
|
||||||
|
state: absent
|
||||||
|
when: nginx_php | length == 0
|
||||||
|
|
||||||
- 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/conf.d/_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
|
||||||
|
|||||||
@@ -1,85 +0,0 @@
|
|||||||
---
|
|
||||||
|
|
||||||
- name: FILE | Create root directory
|
|
||||||
file: >
|
|
||||||
path={{ nginx_root }}
|
|
||||||
state=directory
|
|
||||||
|
|
||||||
- name: FILE | Create root folders (foreach nginx_vhosts)
|
|
||||||
file: >
|
|
||||||
path={{ nginx_root }}/{{ item.name if item.name is string else item.name[0] }}
|
|
||||||
state=directory
|
|
||||||
owner={{ item.owner | default('www-data') }}
|
|
||||||
group={{ item.group | default('www-data') }}
|
|
||||||
mode={{ item.mode | default('0755') }}
|
|
||||||
with_items: nginx_vhosts
|
|
||||||
when: >
|
|
||||||
item.root is not defined and
|
|
||||||
(item.template is defined and item.template != '_proxy') and
|
|
||||||
(item.delete is not defined or not item.delete)
|
|
||||||
|
|
||||||
- name: FILE | Create root public folders (foreach nginx_vhosts)
|
|
||||||
file: >
|
|
||||||
path={{ nginx_root }}/{{ item.name if item.name is string else item.name[0] }}/public
|
|
||||||
state=directory
|
|
||||||
owner={{ item.owner | default('www-data') }}
|
|
||||||
group={{ item.group | default('www-data') }}
|
|
||||||
mode={{ item.mode | default('0755') }}
|
|
||||||
with_items: nginx_vhosts
|
|
||||||
when: >
|
|
||||||
item.root is not defined and
|
|
||||||
(item.template is defined and item.template != '_proxy') and
|
|
||||||
(item.delete is not defined or not item.delete)
|
|
||||||
|
|
||||||
- name: TEMPLATE | Create vhosts
|
|
||||||
template: >
|
|
||||||
src=etc/nginx/sites-available/{{ item.template }}.j2
|
|
||||||
dest=/etc/nginx/sites-available/{{ item.name if item.name is string else item.name[0] }}
|
|
||||||
with_items: nginx_vhosts
|
|
||||||
notify: reload nginx
|
|
||||||
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
|
|
||||||
file: path=/etc/nginx/sites-available/{{ item.name if item.name is string else item.name[0] }} state=absent
|
|
||||||
with_items: nginx_vhosts
|
|
||||||
notify: reload nginx
|
|
||||||
when: item.delete is defined and item.delete
|
|
||||||
|
|
||||||
- name: FILE | Enable vhosts
|
|
||||||
file: >
|
|
||||||
src=/etc/nginx/sites-available/{{ 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] }}
|
|
||||||
state=link
|
|
||||||
with_items: nginx_vhosts
|
|
||||||
notify: reload nginx
|
|
||||||
when: >
|
|
||||||
((item.enable is not defined) or
|
|
||||||
(item.enable is defined and item.enable)) and
|
|
||||||
(item.delete is not defined or not item.delete)
|
|
||||||
|
|
||||||
- name: FILE | Disable vhosts
|
|
||||||
file: path=/etc/nginx/sites-enabled/{{ item.name if item.name is string else item.name[0] }} state=absent
|
|
||||||
with_items: nginx_vhosts
|
|
||||||
notify: reload nginx
|
|
||||||
when: (item.enable is defined and not item.enable) or (item.delete is defined and item.delete)
|
|
||||||
|
|
||||||
#- name: FILE | Create ssl dir per vhost (if needed)
|
|
||||||
# file: dest=/etc/nginx/ssl/{{ item.name }} owner=root mode=0750 state=directory
|
|
||||||
# with_items: nginx_vhosts
|
|
||||||
# when: item.ssl.use is defined and item.ssl.use
|
|
||||||
|
|
||||||
# TODO...
|
|
||||||
#- name: COPY | Deploy SSL keys if needed
|
|
||||||
# copy: src=keys/{{ item.name }}/{{ item.name }}.crt dest=/etc/nginx/ssl/{{ item.name }} mode=660
|
|
||||||
# copy: src=keys/{{ item.name }}/{{ item.name }}.key dest=/etc/nginx/ssl/{{ item.name }} mode=660
|
|
||||||
# with_items: nginx_vhosts
|
|
||||||
# when: item.ssl.use and not generatekey
|
|
||||||
|
|
||||||
# TODO:
|
|
||||||
# - deploy defaults files (index.html/index.php) allready in files/
|
|
||||||
# - work with role "ssl_autosign"
|
|
||||||
|
|
||||||
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_sites":
|
||||||
|
{{ nginx_sites | to_nice_json(indent=8) }}
|
||||||
|
}
|
||||||
7
templates/etc/nginx/conf.d/custom.conf.j2
Normal file
7
templates/etc/nginx/conf.d/custom.conf.j2
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#
|
||||||
|
# {{ ansible_managed }}
|
||||||
|
#
|
||||||
|
|
||||||
|
{% for i in nginx_custom_http %}
|
||||||
|
{{ i }}
|
||||||
|
{% endfor %}
|
||||||
20
templates/etc/nginx/conf.d/php.conf.j2
Normal file
20
templates/etc/nginx/conf.d/php.conf.j2
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#
|
||||||
|
# {{ ansible_managed }}
|
||||||
|
#
|
||||||
|
|
||||||
|
{% for php in nginx_php %}
|
||||||
|
upstream {{ php.upstream_name | default((php.version | php_default_upstream_name)) }} {
|
||||||
|
{% for sock in php.sockets | default([]) %}
|
||||||
|
{% if sock.host is defined %}
|
||||||
|
server {{ sock.host }}:{{ sock.port }} weight={{ sock.weight | default('1') }} max_fails={{ sock.max_fails | default('5') }} fail_timeout={{ sock.fail_timeout | default('10s') }};
|
||||||
|
{% else %}
|
||||||
|
server unix:{{ sock.unix | default((php.version | php_default_upstream_socket)) }} weight={{ sock.weight | default('1') }};
|
||||||
|
{% endif %}
|
||||||
|
{% else %}
|
||||||
|
server unix:{{ php.version | php_default_upstream_socket }} weight=1;
|
||||||
|
{% endfor %}
|
||||||
|
}
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
# vim:filetype=nginx
|
||||||
16
templates/etc/nginx/helper/ssl-legacy.j2
Normal file
16
templates/etc/nginx/helper/ssl-legacy.j2
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#
|
||||||
|
# {{ ansible_managed }}
|
||||||
|
#
|
||||||
|
|
||||||
|
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{% if nginx_version.stdout | version_compare('1.13.0', 'ge') %} TLSv1.3{% endif %};
|
||||||
|
ssl_prefer_server_ciphers on;
|
||||||
|
ssl_session_cache shared:SSL:10m;
|
||||||
|
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains"{% if nginx_version.stdout | version_compare('1.7.5', 'ge') %} always{% endif %};
|
||||||
|
ssl_stapling on;
|
||||||
|
ssl_stapling_verify on;
|
||||||
|
resolver {{ nginx_resolver_hosts | join(' ') }} valid={{ nginx_resolver_valid }};
|
||||||
|
resolver_timeout {{ nginx_resolver_timeout }};
|
||||||
|
ssl_dhparam {{ nginx_dh_path }};
|
||||||
|
|
||||||
|
# vim:filetype=nginx
|
||||||
16
templates/etc/nginx/helper/ssl-strong.j2
Normal file
16
templates/etc/nginx/helper/ssl-strong.j2
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#
|
||||||
|
# {{ ansible_managed }}
|
||||||
|
#
|
||||||
|
|
||||||
|
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
|
||||||
|
ssl_protocols TLSv1 TLSv1.1 TLSv1.2{% if nginx_version.stdout | version_compare('1.13.0', 'ge') %} TLSv1.3{% endif %};
|
||||||
|
ssl_prefer_server_ciphers on;
|
||||||
|
ssl_session_cache shared:SSL:10m;
|
||||||
|
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains"{% if nginx_version.stdout | version_compare('1.7.5', 'ge') %} always{% endif %};
|
||||||
|
ssl_stapling on;
|
||||||
|
ssl_stapling_verify on;
|
||||||
|
resolver {{ nginx_resolver_hosts | join(' ') }} valid={{ nginx_resolver_valid }};
|
||||||
|
resolver_timeout {{ nginx_resolver_timeout }};
|
||||||
|
ssl_dhparam {{ nginx_dh_path }};
|
||||||
|
|
||||||
|
# vim:filetype=nginx
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
#
|
|
||||||
# {{ 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_protocols TLSv1 TLSv1.1 TLSv1.2;
|
|
||||||
ssl_prefer_server_ciphers on;
|
|
||||||
ssl_session_cache shared:SSL:10m;
|
|
||||||
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains";
|
|
||||||
add_header X-Frame-Options DENY;
|
|
||||||
add_header X-Content-Type-Options nosniff;
|
|
||||||
ssl_stapling on;
|
|
||||||
ssl_stapling_verify on;
|
|
||||||
resolver {{ nginx_resolver.hosts | default(['208.67.222.222', '208.67.220.220']) | join(' ') }} valid={{ nginx_resolver.valid}}s;
|
|
||||||
resolver_timeout {{ nginx_resolver.timeout }}s;
|
|
||||||
|
|
||||||
|
|
||||||
# vim:filetype=nginx
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
#
|
|
||||||
# {{ ansible_managed }}
|
|
||||||
#
|
|
||||||
|
|
||||||
ssl_ciphers "AES256+EECDH:AES256+EDH";
|
|
||||||
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
|
|
||||||
ssl_prefer_server_ciphers on;
|
|
||||||
ssl_session_cache shared:SSL:10m;
|
|
||||||
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains";
|
|
||||||
add_header X-Frame-Options DENY;
|
|
||||||
add_header X-Content-Type-Options nosniff;
|
|
||||||
ssl_stapling on;
|
|
||||||
ssl_stapling_verify on;
|
|
||||||
resolver {{ nginx_resolver.hosts | default(['208.67.222.222', '208.67.220.220']) | join(' ') }} valid={{ nginx_resolver.valid}}s;
|
|
||||||
resolver_timeout {{ nginx_resolver.timeout }}s;
|
|
||||||
|
|
||||||
|
|
||||||
# vim:filetype=nginx
|
|
||||||
@@ -5,26 +5,51 @@
|
|||||||
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') %}
|
||||||
|
include {{ nginx_etc_dir }}/modules-enabled/*.conf;
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
events {
|
events {
|
||||||
{% for key, value in nginx_events.iteritems() %}
|
worker_connections {{ nginx_events_worker_connections }};
|
||||||
{{ "\t%-30s %s" | format(key, value) }};
|
multi_accept {{ nginx_events_multi_accept }};
|
||||||
{% endfor %}
|
use {{ nginx_events_use }};
|
||||||
}
|
}
|
||||||
|
|
||||||
http {
|
http {
|
||||||
types_hash_max_size 2048;
|
types_hash_max_size {{ nginx_http_types_hash_max_size }};
|
||||||
include /etc/nginx/mime.types;
|
include {{ nginx_etc_dir }}/mime.types;
|
||||||
default_type application/octet-stream;
|
|
||||||
|
|
||||||
# From Ansible
|
default_type {{ nginx_http_default_type }};
|
||||||
{% for key, value in nginx_http.iteritems() %}
|
access_log {{ nginx_http_access_log }};
|
||||||
{{ "\t%-30s %s" | format(key, value) }};
|
error_log {{ nginx_http_error_log }};
|
||||||
{% endfor %}
|
client_body_buffer_size {{ nginx_http_client_body_buffer_size }};
|
||||||
# /From Ansible
|
client_header_buffer_size {{ nginx_http_client_header_buffer_size }};
|
||||||
|
client_max_body_size {{ nginx_http_client_max_body_size }};
|
||||||
|
large_client_header_buffers {{ nginx_http_large_client_header_buffers }};
|
||||||
|
client_body_timeout {{ nginx_http_client_body_timeout }};
|
||||||
|
client_header_timeout {{ nginx_http_client_header_timeout }};
|
||||||
|
keepalive_timeout {{ nginx_http_keepalive_timeout }};
|
||||||
|
send_timeout {{ nginx_http_send_timeout }};
|
||||||
|
ignore_invalid_headers {{ nginx_http_ignore_invalid_headers }};
|
||||||
|
keepalive_requests {{ nginx_http_keepalive_requests }};
|
||||||
|
recursive_error_pages {{ nginx_http_recursive_error_pages }};
|
||||||
|
sendfile {{ nginx_http_sendfile }};
|
||||||
|
server_name_in_redirect {{ nginx_http_server_name_in_redirect }};
|
||||||
|
server_tokens {{ nginx_http_server_tokens }};
|
||||||
|
tcp_nodelay {{ nginx_http_tcp_nodelay }};
|
||||||
|
tcp_nopush {{ nginx_http_tcp_nopush }};
|
||||||
|
reset_timedout_connection {{ nginx_http_reset_timedout_connection }};
|
||||||
|
gzip {{ nginx_http_gzip }};
|
||||||
|
gzip_buffers {{ nginx_http_gzip_buffers }};
|
||||||
|
gzip_comp_level {{ nginx_http_gzip_comp_level }};
|
||||||
|
gzip_http_version {{ nginx_http_gzip_http_version }};
|
||||||
|
gzip_min_length {{ nginx_http_gzip_min_length }};
|
||||||
|
gzip_types {{ nginx_http_gzip_types }};
|
||||||
|
gzip_vary {{ nginx_http_gzip_vary }};
|
||||||
|
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
|
||||||
|
|||||||
33
templates/etc/nginx/sites-available/_backuppc.j2
Normal file
33
templates/etc/nginx/sites-available/_backuppc.j2
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
{% extends "_base.j2" %}
|
||||||
|
|
||||||
|
{% block root %}
|
||||||
|
root /usr/share/backuppc/cgi-bin;
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block template_try_files %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block template_index %}
|
||||||
|
index index.cgi;
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block template_local_content %}
|
||||||
|
location ~ /\.ht {
|
||||||
|
deny all;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /backuppc/image {
|
||||||
|
alias /usr/share/backuppc/image;
|
||||||
|
expires 60d;
|
||||||
|
}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block template_upstream_location %}
|
||||||
|
location ~ \.cgi$ {
|
||||||
|
gzip off;
|
||||||
|
include fastcgi.conf;
|
||||||
|
fastcgi_pass unix:/var/run/fcgiwrap.socket;
|
||||||
|
fastcgi_index BackupPC_Admin;
|
||||||
|
fastcgi_param SCRIPT_FILENAME /usr/share/backuppc/cgi-bin$fastcgi_script_name;
|
||||||
|
}
|
||||||
|
{% endblock %}
|
||||||
@@ -1,6 +1,39 @@
|
|||||||
{% set __listen = item.listen | default(['80']) %}
|
{% set __proto = item.proto | default(['http']) %}
|
||||||
{% set __listen_ssl = item.listen_ssl | default(['443']) %}
|
{% set __main_name = item | nginx_site_filename %}
|
||||||
|
{% set __listen = item.listen | default([80]) %}
|
||||||
|
{% 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(nginx_servers_default_headers) %}
|
||||||
|
{% 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) -%}
|
||||||
|
{%- if htpasswd_name != false %}
|
||||||
|
{%- for ht in nginx_htpasswd if ht.name == htpasswd_name %}
|
||||||
|
{{ "\t" * indent }}auth_basic "{{ ht.description }}";
|
||||||
|
{{ "\t" * indent }}auth_basic_user_file {{ nginx_htpasswd_dir }}/{{ ht.name }};
|
||||||
|
{%- endfor %}
|
||||||
|
{%- endif %}
|
||||||
|
{%- endmacro %}
|
||||||
|
{% macro ssl(ssl_name) %}
|
||||||
|
{% for sn in nginx_ssl_pairs if sn.name == ssl_name %}
|
||||||
|
ssl_certificate {{ nginx_ssl_dir + '/' + ssl_name + '/' + ssl_name + '.crt' if sn.dest_cert is not defined else sn.dest_cert }};
|
||||||
|
ssl_certificate_key {{ nginx_ssl_dir + '/' + ssl_name + '/' + ssl_name + '.key' if sn.dest_key is not defined else sn.dest_key }};
|
||||||
|
{% endfor %}
|
||||||
|
{%- endmacro %}
|
||||||
|
{% macro httpsredirect(name) %}
|
||||||
|
server {
|
||||||
|
{% for port in __listen %}
|
||||||
|
listen {{ port }}{% if port | int in __http_proxy_protocol_port %} proxy_protocol{% endif %};
|
||||||
|
{% endfor %}
|
||||||
|
server_name {{ name }};
|
||||||
|
location / {
|
||||||
|
return 301 https://{{ name }}{% if '443' not in __listen_ssl and 443 not in __listen_ssl %}:{{ __listen_ssl[0] }}{% endif %}$request_uri;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{% endmacro %}
|
||||||
|
|
||||||
#
|
#
|
||||||
# {{ ansible_managed }}
|
# {{ ansible_managed }}
|
||||||
#
|
#
|
||||||
@@ -9,24 +42,51 @@
|
|||||||
# HTTP
|
# HTTP
|
||||||
#
|
#
|
||||||
server {
|
server {
|
||||||
|
{% if 'http' in __proto %}
|
||||||
{% for port in __listen %}
|
{% for port in __listen %}
|
||||||
listen {{ port }};
|
listen {{ port }}{% if nginx_default_site == __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 %};
|
{% endif %}
|
||||||
|
{% if 'https' in __proto %}
|
||||||
|
{% for port in __listen_ssl %}
|
||||||
|
listen {{ port }}{% if nginx_default_site_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 %}
|
||||||
|
{{ ssl(__ssl_name) }}
|
||||||
|
{% if item.ssl_template is not defined or item.ssl_template != false %}
|
||||||
|
include {{ nginx_helper_dir + '/ssl-' + item.ssl_template | default('strong') }};
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
server_name {% if item.name is string %}{{ item.name }}{% else %}{{ "\n\t\t" }}{{ item.name | join("\n\t\t") }}{% endif %};
|
||||||
|
{% block root %}
|
||||||
{% if item.root is defined %}
|
{% if item.root is defined %}
|
||||||
root {{ item.root }};
|
root {{ item.root }};
|
||||||
{% else %}
|
{% else %}
|
||||||
root {{ nginx_root }}/{{ item.name if item.name is string else item.name[0] }}/public;
|
root {{ nginx_root }}/{{ __main_name }}/public;
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% endblock %}
|
||||||
{% block template_index %}
|
{% block template_index %}
|
||||||
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 %}
|
||||||
|
{{ htpasswd(item.htpasswd, 1) }}
|
||||||
|
{% 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 / {
|
||||||
@@ -41,12 +101,26 @@ 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 %}
|
||||||
|
{% if item.manage_local_content is not defined or item.manage_local_content %}
|
||||||
location ~ /\.ht {
|
location ~ /\.ht {
|
||||||
deny all;
|
deny all;
|
||||||
}
|
}
|
||||||
|
|
||||||
{% block template_local_content %}
|
|
||||||
{% if item.manage_local_content is not defined or item.manage_local_content %}
|
|
||||||
location = /favicon.ico {
|
location = /favicon.ico {
|
||||||
expires 30d;
|
expires 30d;
|
||||||
access_log off;
|
access_log off;
|
||||||
@@ -60,40 +134,34 @@ 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() %}
|
access_log {{ nginx_log_dir }}/{{ __main_name }}_access.log combined;
|
||||||
location {{ location }} {
|
|
||||||
{% for opt in opts %}
|
|
||||||
{{ opt }}
|
|
||||||
{% endfor %}
|
|
||||||
}
|
|
||||||
{% endfor %} # <-- Custom locations
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if item.use_access_log is defined and item.use_access_log %}
|
|
||||||
access_log {{ nginx_log_dir }}/{{ item.name[0] }}_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 %}
|
||||||
error_log {{ nginx_log_dir }}/{{ item.name[0] }}_error.log {{ nginx_error_log_level }};
|
{% 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 }};
|
||||||
{% else %}
|
{% else %}
|
||||||
error_log off;
|
error_log off;
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
}
|
}
|
||||||
|
|
||||||
{#
|
{% if item.redirect_https is defined and item.redirect_https %}
|
||||||
ssl on;
|
#
|
||||||
ssl_certificate {{ nginx_ssl_dir }}/{{ item.name }}/{{ item.name }}.crt;
|
# Redirect HTTP to HTTPS
|
||||||
ssl_certificate_key {{ nginx_ssl_dir }}/{{ item.name }}/{{ item.name }}.key;
|
#
|
||||||
include /etc/nginx/helpers/ssl-{{ item.ssl.template | default('strong') }};
|
{% if item.name is string %}
|
||||||
#}
|
{{ httpsredirect(item.name) }}
|
||||||
|
{% else %}
|
||||||
|
{% for i in item.name %}
|
||||||
# HTTPS
|
{{ httpsredirect(i) }}
|
||||||
#server {
|
{% endfor %}
|
||||||
#}
|
{% endif %}
|
||||||
|
{% 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 %}
|
||||||
#
|
#
|
||||||
@@ -101,11 +169,30 @@ include /etc/nginx/helpers/ssl-{{ item.ssl.template | default('strong') }};
|
|||||||
#
|
#
|
||||||
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://{{ item.name[0] }}$request_uri;
|
location / {
|
||||||
|
return 301 $scheme://{{ item.name if item.name is string else item.name[0] }}$request_uri;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{% if 'https' in __proto %}
|
||||||
|
server {
|
||||||
|
{% for port in __listen_ssl %}
|
||||||
|
listen {{ port }}{% if nginx_default_site_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 %}
|
||||||
|
{{ ssl(__ssl_name) }}
|
||||||
|
{% if item.ssl_template is not defined or item.ssl_template != false %}
|
||||||
|
include {{ nginx_helper_dir + '/ssl-' + item.ssl_template | default('strong') }};
|
||||||
|
{% endif %}
|
||||||
|
server_name {% if item.redirect_from is string %}{{ item.redirect_from }}{% else %}{{ "\n\t\t" }}{{ item.redirect_from | join("\n\t\t") }}{% endif %};
|
||||||
|
location / {
|
||||||
|
return 301 https://{{ item.name if item.name is string else item.name[0] }}{% if '443' not in __listen_ssl and 443 not in __listen_ssl %}:{{ __listen_ssl[0] }}{% endif %}$request_uri;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
# vim:filetype=nginx
|
# vim:filetype=nginx
|
||||||
|
|||||||
59
templates/etc/nginx/sites-available/_nagios3.j2
Normal file
59
templates/etc/nginx/sites-available/_nagios3.j2
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
{% extends "_php.j2" %}
|
||||||
|
|
||||||
|
{% block root %}
|
||||||
|
root {{ nginx_nagios_root }};
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block template_try_files %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block template_index %}
|
||||||
|
index index.php index.html;
|
||||||
|
{% 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 %}
|
||||||
|
location ~ /\.ht {
|
||||||
|
deny all;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /stylesheets {
|
||||||
|
{% if nginx_nagios_stylesheets is defined %}
|
||||||
|
alias {{ nginx_nagios_stylesheets }};
|
||||||
|
{% endif %}
|
||||||
|
expires 60d;
|
||||||
|
}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block template_upstream_location %}
|
||||||
|
{% if ansible_distribution == 'Debian' %}
|
||||||
|
location /cgi-bin/nagios3 {
|
||||||
|
root /usr/lib;
|
||||||
|
{% elif ansible_distribution == 'FreeBSD' %}
|
||||||
|
location /cgi-bin {
|
||||||
|
{% endif %}
|
||||||
|
try_files $uri =404;
|
||||||
|
include fastcgi.conf;
|
||||||
|
fastcgi_pass unix:{{ nginx_fcgiwrap_sock }};
|
||||||
|
fastcgi_param AUTH_USER $remote_user;
|
||||||
|
fastcgi_param REMOTE_USER $remote_user;
|
||||||
|
}
|
||||||
|
location ~ \.php$ {
|
||||||
|
fastcgi_pass {{ php_upstream }};
|
||||||
|
fastcgi_index index.php;
|
||||||
|
include fastcgi.conf;
|
||||||
|
}
|
||||||
|
{% endblock %}
|
||||||
@@ -1,25 +1,34 @@
|
|||||||
{% extends "_base.j2" %}
|
{% extends "_base.j2" %}
|
||||||
|
|
||||||
|
{% if item.php_version is defined %}
|
||||||
|
{% set php_info = 'Explicit PHP version on site' %}
|
||||||
|
{% set php_upstream = (nginx_php|selectattr('version', 'equalto', item.php_version)|first).upstream_name | default(item.php_version | php_default_upstream_name) %}
|
||||||
|
{% elif item.php_upstream is defined %}
|
||||||
|
{% set php_info = 'Explicit Nginx/PHP upstream on site' %}
|
||||||
|
{% set php_upstream = item.php_upstream %}
|
||||||
|
{% else %}
|
||||||
|
{% set php_info = 'Warning: using first PHP version on config' %}
|
||||||
|
{% set php_upstream = nginx_php.0.upstream_name | default(nginx_php.0.version | php_default_upstream_name) %}
|
||||||
|
{% 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 %}
|
||||||
|
|
||||||
{% block template_try_files %}
|
{% block template_try_files %}
|
||||||
try_files {{ override_try_files | default('$uri $uri/ /index.php') }};
|
try_files {{ override_try_files | default('$uri $uri/ =404') }};
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block template_upstream_location %}
|
{% block template_upstream_location %}
|
||||||
location ~ \.php$ {
|
location ~ \.php$ {
|
||||||
fastcgi_pass php;
|
# {{ php_info }}
|
||||||
|
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 %}
|
||||||
{{ param }}
|
{{ param }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if nginx_version.stdout | version_compare('1.6.1', 'lt') %}
|
|
||||||
include fastcgi_params;
|
|
||||||
{% else %}
|
|
||||||
include fastcgi.conf;
|
include fastcgi.conf;
|
||||||
{% endif %}
|
|
||||||
}
|
}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@@ -2,18 +2,15 @@
|
|||||||
|
|
||||||
{% block template_upstream_location %}
|
{% block template_upstream_location %}
|
||||||
location = /index.php {
|
location = /index.php {
|
||||||
fastcgi_pass php;
|
# {{ php_info }}
|
||||||
|
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 %}
|
||||||
{{ param }}
|
{{ param }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if nginx_version.stdout | version_compare('1.6.1', 'lt') %}
|
|
||||||
include fastcgi_params;
|
|
||||||
{% else %}
|
|
||||||
include fastcgi.conf;
|
include fastcgi.conf;
|
||||||
{% endif %}
|
|
||||||
}
|
}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|||||||
19
templates/etc/nginx/sites-available/_php_index2.j2
Normal file
19
templates/etc/nginx/sites-available/_php_index2.j2
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
{% extends "_php.j2" %}
|
||||||
|
|
||||||
|
{% block template_try_files %}
|
||||||
|
try_files {{ override_try_files | default('$uri $uri/ /index.php') }};
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block template_upstream_location %}
|
||||||
|
location = /index.php {
|
||||||
|
# {{ php_info }}
|
||||||
|
fastcgi_pass {{ php_upstream }};
|
||||||
|
fastcgi_index index.php;
|
||||||
|
{% if item.upstream_params is defined and item.upstream_params is iterable %}
|
||||||
|
{% for param in item.upstream_params %}
|
||||||
|
{{ param }}
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
include fastcgi.conf;
|
||||||
|
}
|
||||||
|
{% endblock %}
|
||||||
@@ -1,16 +1,14 @@
|
|||||||
{% extends "_base.j2" %}
|
{% extends "_base.j2" %}
|
||||||
|
|
||||||
{% block template_try_files %}
|
{% block root %}
|
||||||
proxy_set_header Host $host;
|
{% if item.root is defined %}
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
root {{ item.root }};
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
{% endif %}
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
{% endblock %}
|
||||||
|
|
||||||
proxy_pass http://{{ item.upstream_name }};
|
|
||||||
proxy_read_timeout 90;
|
|
||||||
|
|
||||||
{#proxy_redirect http://{{ upstream.name }} https://jenkins.domain.tld;#}
|
|
||||||
|
|
||||||
|
{% block template_try_files %}
|
||||||
|
include {{ nginx_etc_dir }}/proxy_params;
|
||||||
|
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 %}
|
||||||
{{ param }}
|
{{ param }}
|
||||||
|
|||||||
14
templates/etc/nginx/sites-available/_redirect.j2
Normal file
14
templates/etc/nginx/sites-available/_redirect.j2
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{% extends "_base.j2" %}
|
||||||
|
|
||||||
|
{% block root %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block template_index %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block template_try_files %}
|
||||||
|
return {{ item.redirect_to_code | default('302') }} {{ item.redirect_to }}$request_uri;
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block template_local_content %}
|
||||||
|
{% endblock %}
|
||||||
@@ -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 %}
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
#
|
|
||||||
# {{ ansible_managed }}
|
|
||||||
#
|
|
||||||
|
|
||||||
upstream php {
|
|
||||||
{% for item in nginx_php_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 %}
|
|
||||||
}
|
|
||||||
|
|
||||||
# vim:filetype=nginx
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
FROM williamyeh/ansible:debian8-onbuild
|
|
||||||
|
|
||||||
RUN apt-get update
|
|
||||||
CMD ["sh", "tests/test.sh"]
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
FROM williamyeh/ansible:debian7-onbuild
|
|
||||||
|
|
||||||
RUN apt-get update
|
|
||||||
CMD ["sh", "tests/test.sh"]
|
|
||||||
19
tests/file/test.crt
Normal file
19
tests/file/test.crt
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIIDHTCCAgWgAwIBAgIJAJzUwbFlhyxIMA0GCSqGSIb3DQEBCwUAMCUxIzAhBgNV
|
||||||
|
BAMMGnRlc3Qtc3NsLXByZWRlcGxveWVkLmxvY2FsMB4XDTE2MDExMjE2MDUxNVoX
|
||||||
|
DTI2MDEwOTE2MDUxNVowJTEjMCEGA1UEAwwadGVzdC1zc2wtcHJlZGVwbG95ZWQu
|
||||||
|
bG9jYWwwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDm4q94vffiU89G
|
||||||
|
GO7rjDfr3C32tH9sM5sXqJT+7N5BLYLF0iSRIvy33MtwFu//TV3f+8nLlQuHYVVk
|
||||||
|
L6NEvaL8lh+nRexCQ/y+aXMh7lMhuwPXGgPR1LXsTqyDXbmV9c7k/Kwx5qHAcOb9
|
||||||
|
d9YzmcOSO4M9v3WMl/4Zw2J7zNYruypxNBgFEwFx3NJ3AztACMYoVOIR5mS8ARX6
|
||||||
|
xea4ddii1F41Vch+eiCGP9VZwDhEujhjy9PXvdBtYNwggM6d82Df9wwaFyIW5DU4
|
||||||
|
PhpgAngvE2keY0GLy/LaXa6LAW+TCfPMRT2RtDuvqWr+useWF+O3n81TZqM/G7LV
|
||||||
|
9iPxkkRNAgMBAAGjUDBOMB0GA1UdDgQWBBSzXW5UY02/S0xrrobZCVOhas6VeDAf
|
||||||
|
BgNVHSMEGDAWgBSzXW5UY02/S0xrrobZCVOhas6VeDAMBgNVHRMEBTADAQH/MA0G
|
||||||
|
CSqGSIb3DQEBCwUAA4IBAQC0+Tr0w9aG4f3LG3+WRGKfMopKICNEkA7JrPrvVUq8
|
||||||
|
7UgtdrpOUZAL5AKxVVo1rHDdoL/VpjdqHdhyPzaSUl8hppCFsWmdQh4wLKGoyvcN
|
||||||
|
AqSGpXTeLSoFJ357F2OIQpXm2lfT2fVGebwyCNFkwpp7klFnmOusSl2/v5Y5cz+A
|
||||||
|
WvWrDg3jsNglx3mNLVcjbOSnen2PsZSmcVo27D0el6oDju8jjstyJ+Dvu0WP+CDL
|
||||||
|
s/VolFdbei7d4r2dj86OZ/BCZurltyc0wI3NMOdUuA7q4f1MPTRu7qr/ua5ItK92
|
||||||
|
Avc+Gjn/Y/aIhzKpPicJQDK6FzxjfhCc8xtk0EjB4IpP
|
||||||
|
-----END CERTIFICATE-----
|
||||||
28
tests/file/test.key
Normal file
28
tests/file/test.key
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
-----BEGIN PRIVATE KEY-----
|
||||||
|
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDm4q94vffiU89G
|
||||||
|
GO7rjDfr3C32tH9sM5sXqJT+7N5BLYLF0iSRIvy33MtwFu//TV3f+8nLlQuHYVVk
|
||||||
|
L6NEvaL8lh+nRexCQ/y+aXMh7lMhuwPXGgPR1LXsTqyDXbmV9c7k/Kwx5qHAcOb9
|
||||||
|
d9YzmcOSO4M9v3WMl/4Zw2J7zNYruypxNBgFEwFx3NJ3AztACMYoVOIR5mS8ARX6
|
||||||
|
xea4ddii1F41Vch+eiCGP9VZwDhEujhjy9PXvdBtYNwggM6d82Df9wwaFyIW5DU4
|
||||||
|
PhpgAngvE2keY0GLy/LaXa6LAW+TCfPMRT2RtDuvqWr+useWF+O3n81TZqM/G7LV
|
||||||
|
9iPxkkRNAgMBAAECggEAEEeZkczrRpUcP1gQuKEZbFMJFqUhevKkk+V6JAN1pGje
|
||||||
|
GK65j1ZFNX2nBo9Hetvsq5doYidvOat+RuMpAvbQIDlBoBzJDN8YWiC7UoAocm9q
|
||||||
|
VOdrr4btEO13MogQRuefH/xE8/vMGfKcBvFFNDw6UvxJQ7hVRIWPECf7sLj/vPOC
|
||||||
|
OpMKghxcabQqidMPKyyHVPhQjuIvqW/SqBFpD+Ul0Ja1QGdx+p+/EwVmXnei6Kr8
|
||||||
|
/ypULreHqIlBLD6McfFehxDV0m5U7qXb5xK3zdUurIhZixKLjbdRrorNInfEvlOh
|
||||||
|
vDy+hsF5GSzvn9dRrMAy/QcRPpXU47VNYZ5BfdCBTQKBgQD8VCbdpG5siXSlIjZd
|
||||||
|
xypgK1ttp8udTPWC1trnAc+Ku9O+cGmvABxYJA1iR/GDpSfMxglB7OhSecywKrr+
|
||||||
|
S7Yjs9e/dyBmvF7U15JJaGp+db2Ct64z7MvqkwSJ5a0qrrZJRFetDdqdH9FPvURs
|
||||||
|
B147jbKsPiGcljjXbZlOBHJH9wKBgQDqPqoA3VqYOmvR7Ei8/skY2EOpFpOhSNko
|
||||||
|
ARFwUsDNHRk677URH97TCHq5UrwubfCeIcIptXHrMfaTsfq8vPLPykReIMRaknxf
|
||||||
|
DULJPHSoeBLrCAZmaWF1JVyYhrLhHNAzQ3u7a/kYIJm87FEZy3Ml6FSZmIGbRBqx
|
||||||
|
zqZYKoHs2wKBgQD469tbk7cLg556uYGAidYYAS20w29uwlkAtgxFD9g6OIjuud7I
|
||||||
|
MQfFO+uoJOjwwaC9ti+zxY56roVq1PybmP0Zw3T3AQIJ15KFzhQWLte/4U8PATzt
|
||||||
|
JJEV2+sCTn3COZDCPpVvttcPYjAOxdwV5j7j6Sl2GeT2oIt6mjg+asyCiQKBgQDk
|
||||||
|
LPxu8TBRfv8OMqs8Jrf/EpL9/7b48bxOwpOZJZMXelPcXCm1r6TfTrA1HAmg9Ijh
|
||||||
|
kKLQ/CUm5Ll7b3B+L1Qa4r2sLyD11SF/eaxn2BMPFD/hYCTT160ObsF+9h8DN4z7
|
||||||
|
kq3RiMDRJth69nuds9fLwj++ipcdhr62G0VgNq/u5wKBgCz/I5J3tPNjrU9YampR
|
||||||
|
0gNnUkUfJWbiVMsG9uwL9l0L/ZzQHvELJ523QXQ0v/e/szHCyoX319u8HEQlC0Jw
|
||||||
|
Twlj81HDZzruDUB/mcH6Ee3zHKOmmF6ma+CgoYJJElKW89MUttPdmkH2J1QqLz+7
|
||||||
|
EGREwqjr8/wm22DzKNiyDXJ0
|
||||||
|
-----END PRIVATE KEY-----
|
||||||
20
tests/includes/post_Debian.yml
Normal file
20
tests/includes/post_Debian.yml
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
- name: APT | Install webapps
|
||||||
|
apt:
|
||||||
|
pkg: "{{ item }}"
|
||||||
|
state: present
|
||||||
|
install_recommends: no
|
||||||
|
with_items:
|
||||||
|
- backuppc
|
||||||
|
|
||||||
|
- name: APT | Install nagios3 (only on old Debian releases)
|
||||||
|
apt:
|
||||||
|
pkg: nagios3
|
||||||
|
state: present
|
||||||
|
when: ansible_distribution_major_version | version_compare('9', 'lt')
|
||||||
|
|
||||||
|
- name: SERVICE | Ensure backuppc is started
|
||||||
|
service:
|
||||||
|
name: backuppc
|
||||||
|
state: started
|
||||||
33
tests/includes/post_FreeBSD.yml
Normal file
33
tests/includes/post_FreeBSD.yml
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
#- 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
|
||||||
99
tests/includes/pre_Debian.yml
Normal file
99
tests/includes/pre_Debian.yml
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
- name: APT_REPOSITORY | Install backports
|
||||||
|
apt_repository:
|
||||||
|
repo: 'deb http://httpredir.debian.org/debian {{ ansible_distribution_release }}-backports main'
|
||||||
|
state: present
|
||||||
|
when: nginx_backports
|
||||||
|
|
||||||
|
- 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 | default(false)
|
||||||
|
|
||||||
|
- block:
|
||||||
|
|
||||||
|
- name: APT | Install apt-transport-https
|
||||||
|
apt:
|
||||||
|
pkg: apt-transport-https
|
||||||
|
update_cache: yes
|
||||||
|
cache_valid_time: 3600
|
||||||
|
|
||||||
|
- name: APT_KEY | Install GPG key
|
||||||
|
apt_key:
|
||||||
|
url: 'https://packages.sury.org/php/apt.gpg'
|
||||||
|
|
||||||
|
- name: APT_REPOSITORY | Add APT repository
|
||||||
|
apt_repository:
|
||||||
|
repo: 'deb https://packages.sury.org/php {{ ansible_distribution_release }} main'
|
||||||
|
|
||||||
|
when: sury | default(false)
|
||||||
|
|
||||||
|
- name: APT | Install needed packages
|
||||||
|
apt:
|
||||||
|
pkg: "{{ item }}"
|
||||||
|
update_cache: yes
|
||||||
|
cache_valid_time: 3600
|
||||||
|
state: present
|
||||||
|
with_items:
|
||||||
|
- cron
|
||||||
|
- curl
|
||||||
|
- fcgiwrap
|
||||||
|
- jq
|
||||||
|
- nghttp2
|
||||||
|
- strace
|
||||||
|
- vim
|
||||||
|
- unzip
|
||||||
|
|
||||||
|
- name: APT | Install daemonize from Stretch
|
||||||
|
apt:
|
||||||
|
deb: http://ftp.us.debian.org/debian/pool/main/d/daemonize/daemonize_1.7.7-1+b1_amd64.deb
|
||||||
|
|
||||||
|
- name: APT | Install PHP
|
||||||
|
apt:
|
||||||
|
pkg: "{{ item.version | php_fpm_package }}"
|
||||||
|
update_cache: yes
|
||||||
|
cache_valid_time: 3600
|
||||||
|
state: present
|
||||||
|
with_items: "{{ nginx_php }}"
|
||||||
|
register: apt_php
|
||||||
|
|
||||||
|
- name: SERVICE | Force start fcgiwrap
|
||||||
|
service:
|
||||||
|
name: "fcgiwrap"
|
||||||
|
state: started
|
||||||
|
|
||||||
|
# Bypasses Ansible 2.4 issue (cannot use service module)... With service module... php is not really started!
|
||||||
|
- name: COMMAND | Force start PHP
|
||||||
|
command: "service {{ item.version | php_fpm_service }} start"
|
||||||
|
with_items: "{{ nginx_php }}"
|
||||||
|
when: apt_php.changed
|
||||||
|
|
||||||
|
- name: GET_URL | Download ngrok
|
||||||
|
get_url:
|
||||||
|
url: "https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip"
|
||||||
|
dest: "/tmp/ngrok.zip"
|
||||||
|
|
||||||
|
- name: UNARCHIVE | Uncompress ngrok
|
||||||
|
unarchive:
|
||||||
|
src: "/tmp/ngrok.zip"
|
||||||
|
dest: "/tmp"
|
||||||
|
remote_src: yes
|
||||||
|
|
||||||
|
- name: SET_FACT | ngrok_path
|
||||||
|
set_fact:
|
||||||
|
ngrok_path: '/tmp/ngrok'
|
||||||
65
tests/includes/pre_FreeBSD.yml
Normal file
65
tests/includes/pre_FreeBSD.yml
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
- name: SET_FACT | FreeBSD web user
|
||||||
|
set_fact:
|
||||||
|
nginx_pkgng_package: 'nginx-full'
|
||||||
|
nginx_user: 'www'
|
||||||
|
nginx_php:
|
||||||
|
- version: '7.2'
|
||||||
|
sockets:
|
||||||
|
- host: '127.0.0.1'
|
||||||
|
port: 9000
|
||||||
|
nginx_load_modules:
|
||||||
|
- /usr/local/libexec/nginx/ngx_http_geoip_module.so
|
||||||
|
ngrok_path: '/usr/local/bin/ngrok'
|
||||||
|
|
||||||
|
- name: PKGNG | Install needed packages
|
||||||
|
pkgng:
|
||||||
|
pkg: "{{ item }}"
|
||||||
|
state: present
|
||||||
|
with_items:
|
||||||
|
- curl
|
||||||
|
- daemonize
|
||||||
|
- fcgiwrap
|
||||||
|
- GeoIP
|
||||||
|
- jq
|
||||||
|
- nghttp2
|
||||||
|
- php72
|
||||||
|
- vim
|
||||||
|
|
||||||
|
- name: COMMAND | Get geoip database
|
||||||
|
command: geoipupdate.sh
|
||||||
|
args:
|
||||||
|
creates: /usr/local/share/GeoIP/GeoIP.dat
|
||||||
|
|
||||||
|
- name: SERVICE | Force start services
|
||||||
|
service:
|
||||||
|
name: "{{ item }}"
|
||||||
|
state: started
|
||||||
|
enabled: yes
|
||||||
|
register: sf
|
||||||
|
with_items:
|
||||||
|
- php-fpm
|
||||||
|
- fcgiwrap
|
||||||
|
|
||||||
|
- name: STAT | Check ports
|
||||||
|
stat:
|
||||||
|
path: /usr/ports
|
||||||
|
register: ports
|
||||||
|
|
||||||
|
- block:
|
||||||
|
|
||||||
|
- name: COMMAND | Get ports
|
||||||
|
command: portsnap fetch --interactive
|
||||||
|
|
||||||
|
- name: COMMAND | Extract ports
|
||||||
|
command: portsnap extract
|
||||||
|
no_log: true
|
||||||
|
|
||||||
|
when: not ports.stat.exists
|
||||||
|
|
||||||
|
- name: SHELL | Install ngrok
|
||||||
|
shell: make install clean DISABLE_LICENSES=yes
|
||||||
|
args:
|
||||||
|
chdir: /usr/ports/security/ngrok
|
||||||
|
creates: "{{ ngrok_path }}"
|
||||||
18
tests/includes/pre_common.yml
Normal file
18
tests/includes/pre_common.yml
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
- name: SHELL | Start ngrok
|
||||||
|
shell: daemonize -l /tmp/ngrok.lock {{ ngrok_path }} http 8888 -bind-tls=false
|
||||||
|
failed_when: false
|
||||||
|
changed_when: ngrok.stderr.find("Can't lock the lock file") == -1
|
||||||
|
register: ngrok
|
||||||
|
|
||||||
|
- name: WAIT_FOR | ngrok started
|
||||||
|
wait_for:
|
||||||
|
delay: 2
|
||||||
|
port: 4040
|
||||||
|
when: ngrok.changed
|
||||||
|
|
||||||
|
- name: SHELL | Get ngrok public address
|
||||||
|
shell: curl 'http://127.0.0.1:4040/api/tunnels/command_line' | jq '.public_url' | grep -oE '[[:alnum:]]+\.ngrok\.io'
|
||||||
|
register: ngrok
|
||||||
|
changed_when: false
|
||||||
@@ -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)
|
|
||||||
505
tests/test.yml
505
tests/test.yml
@@ -2,12 +2,41 @@
|
|||||||
|
|
||||||
- hosts: all
|
- hosts: all
|
||||||
pre_tasks:
|
pre_tasks:
|
||||||
- apt: pkg={{ item }} update_cache=yes cache_valid_time=3600 state=present
|
- name: INCLUDE | Pre_tasks related to OS version
|
||||||
with_items:
|
include: "includes/pre_{{ ansible_distribution }}.yml"
|
||||||
- php5-fpm
|
|
||||||
- curl
|
- name: INCLUDE | Pre_tasks common
|
||||||
|
include: "includes/pre_common.yml"
|
||||||
|
|
||||||
|
- name: FILE | Create an internal SSL dir
|
||||||
|
file:
|
||||||
|
path: "{{ int_ansible_ssl_dir }}"
|
||||||
|
state: directory
|
||||||
|
|
||||||
|
- name: COPY | Deploy test certificate
|
||||||
|
copy:
|
||||||
|
src: "file/test.crt"
|
||||||
|
dest: "{{ int_ansible_ssl_dir }}/test.crt"
|
||||||
|
|
||||||
|
- name: COPY | Deploy test key
|
||||||
|
copy:
|
||||||
|
src: "file/test.key"
|
||||||
|
dest: "{{ int_ansible_ssl_dir }}/test.key"
|
||||||
|
|
||||||
|
- name: LINEINFILE | Add all hosts in /etc/hosts
|
||||||
|
lineinfile:
|
||||||
|
line: "127.0.0.1\tlocalhost {% for s in nginx_sites %}{% if s.name is string %}{{ s.name }}{% else %}{% for n in s.name %}{{ n }} {% endfor %}{% endif %} {% if s.redirect_from is defined %}{% for rf in s.redirect_from %}{{ rf }} {% endfor %}{% endif %}{% endfor %}"
|
||||||
|
regexp: '^127\.0\.0\.1'
|
||||||
|
dest: "/etc/hosts"
|
||||||
|
unsafe_writes: yes
|
||||||
|
|
||||||
vars:
|
vars:
|
||||||
nginx_php: true
|
# Internal vars
|
||||||
|
int_ansible_ssl_dir: '/etc/ansible-ssl'
|
||||||
|
# Role vars
|
||||||
|
nginx_worker_processes: 1 # Ansible+FreeBSD can't detect CPU number
|
||||||
|
nginx_apt_package: 'nginx-extras'
|
||||||
|
nginx_module_packages: ['libnginx-mod-http-headers-more-filter']
|
||||||
nginx_upstreams:
|
nginx_upstreams:
|
||||||
- name: 'test'
|
- name: 'test'
|
||||||
servers:
|
servers:
|
||||||
@@ -15,14 +44,113 @@
|
|||||||
max_conns: 150
|
max_conns: 150
|
||||||
weight: 10
|
weight: 10
|
||||||
down: false
|
down: false
|
||||||
nginx_vhosts:
|
- name: 'test-absent'
|
||||||
|
servers:
|
||||||
|
- path: '127.0.0.1:80'
|
||||||
|
max_conns: 150
|
||||||
|
weight: 10
|
||||||
|
down: false
|
||||||
|
state: 'absent'
|
||||||
|
nginx_htpasswd:
|
||||||
|
- name: 'hello'
|
||||||
|
description: 'Please login!'
|
||||||
|
users:
|
||||||
|
- name: 'hx'
|
||||||
|
password: 'asdfg'
|
||||||
|
state: 'absent'
|
||||||
|
- name: 'hanx'
|
||||||
|
password: 'qwerty'
|
||||||
|
- name: 'nagios'
|
||||||
|
description: 'Please login to Nagios!'
|
||||||
|
users:
|
||||||
|
- name: 'nagiosadmin'
|
||||||
|
password: 'nagios'
|
||||||
|
- name: 'deleteme'
|
||||||
|
description: 'Please login!'
|
||||||
|
users: []
|
||||||
|
state: 'absent'
|
||||||
|
nginx_acmesh: true
|
||||||
|
nginx_acmesh_test: true
|
||||||
|
nginx_ssl_pairs:
|
||||||
|
- name: '{{ ngrok.stdout }}'
|
||||||
|
acme: true
|
||||||
|
acme_port: 8888
|
||||||
|
- name: 'test-ssl-predeployed.local'
|
||||||
|
dest_key: "{{ int_ansible_ssl_dir }}/test.key"
|
||||||
|
dest_cert: "{{ int_ansible_ssl_dir }}/test.crt"
|
||||||
|
- name: 'test-ssl.local'
|
||||||
|
key: |
|
||||||
|
-----BEGIN RSA PRIVATE KEY-----
|
||||||
|
MIIEpAIBAAKCAQEAvavrJWFp3Al2VwRgKx+4Y2mbRRvoxvyd2pyN0xMJ/tCJscaG
|
||||||
|
8s60v6WZ9FcCOeMkSI2DXsk4z7pbQdQn0h2GDr/5MOJkPAVWSWEN46tpaLZ3v0zp
|
||||||
|
88ZIbnEk1G0PsdFuW/pnLsakPlAMrl1VArFsV6YsatLt30UIYYcRO97StkoOehCx
|
||||||
|
A5w+XqtfHZeQZ0/DS81633gwYUcMuSTUFZ60r7ge1/m77DTSKg3rTVk5sebP8cjS
|
||||||
|
+aWHvxP/GyvvDsT+3gjRJx2/5O3JkfH0zaOsaU2Avj0PR0c5rhynrNO/l1k+GJJB
|
||||||
|
cbBrM+yA8Ofzp4oXUrCfaIq3RuL3Pd+khcKsiwIDAQABAoIBAQCPpAMQ7BUfbosQ
|
||||||
|
m1+5SOx7XR8Z12kSSX3CcY12rJSFRakB2TeZ6rE38lIFmV82N67iw0kaH4nGx3sU
|
||||||
|
/3aoyXMc+IXfX5RJYEFYkQfTw5ywkH9fgQAsfZ2dBlK+DVo1cEYDoj9CTW1VQ4pX
|
||||||
|
Ape+0l8agd5hiBxdWgpe0ctbbARnx584viLiA/iPBDNxKi9zEYw+WP7hSj5QWahr
|
||||||
|
a09tubcC4L6tjvv8CoZTRSKfCW64vWRDvE6vmA+zJN9Arc1WTYzF1KO1Gybwf8h7
|
||||||
|
stJb191smAgGDFhKo0j58ncyAnrS1k4mapm86QQhlfIA6DKvvC0qm3KdQns5b7HM
|
||||||
|
PyzW0hwBAoGBAO2mTVTOsziom9vtBwM0nRMMEgynR2X3EKMJz2mjcCf66f1F+aQ5
|
||||||
|
DvQFM2V8S2s1nGnPh8NKKZ8DxW1NKuR4qx82zeAXpUs9ibHxOnw4YRC485zqc2Wt
|
||||||
|
fSO1OEDYeKyzWP1nGGtCntYUXzJnWn/wz0mBGKzLKTuLwyFIKx1b7bybAoGBAMxR
|
||||||
|
N+lT57rX6d4GUqcgNOuWMZ/D8egnE5+hsoiFnHOisRLOgUgBBSy4rwAZx+rdHYT+
|
||||||
|
RO11L1PLYEzyvnO0f13R+N7aqKwNXDSzZGA+jb4pjkVidIC2smG/JYKJH5Z+kakw
|
||||||
|
mwMKP0wdRZJsCaMgScHmWJS8d6Ox/XJJoWrTWTbRAoGAWJlEgVaiaIArwz1F/QLz
|
||||||
|
gHNik0cWDkSi9jWlFxwwpycbbypUXM5M7dq2g6JoN6sACk6trbgLdlYgl5RKZm06
|
||||||
|
VuPGs0H9hOSHXkix5jfasDJT2G9r4D9ixRo9w6cwriobBjYWW3612tgzeYYgrkwn
|
||||||
|
655uhZUkZSfA8rqGIGbyZfsCgYAf5WH8G+wmIATTc1s92epJCOZwUY+XNVp75itP
|
||||||
|
4sPczX4lOHW4PuiG5cH0GxI5mRE9rNAn3c5on2xGNvMCbyAfDmNyruH8Eg3d8E9w
|
||||||
|
MvO/xw79x/P2EA9i8QszCKMUxGeK6RqZ6+SbxkoRJKqQe77n9UTI228179hoGhSH
|
||||||
|
77ySsQKBgQC8SSZn6a8PpSIIFXB9WCFMwfGFYbUz0wvpaeZP8GKx3BEzMeJqSUaJ
|
||||||
|
hrQgpwQXkueeamlCQcvV3AUCoBRWTYRLDrWiUIXuIgikDWBFp6TBvTnVRI7iktly
|
||||||
|
fNED7jXOSjJqnFmdkZlAI5V8dM++mVYVykJD6jcaVRQvxqFLrhSaRg==
|
||||||
|
-----END RSA PRIVATE KEY-----
|
||||||
|
cert: |
|
||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIIDBTCCAe2gAwIBAgIJALKJfbk5vuieMA0GCSqGSIb3DQEBBQUAMBkxFzAVBgNV
|
||||||
|
BAMMDnRlc3Qtc3NsLmxvY2FsMB4XDTE2MDExMTE2NDI0NFoXDTI2MDEwODE2NDI0
|
||||||
|
NFowGTEXMBUGA1UEAwwOdGVzdC1zc2wubG9jYWwwggEiMA0GCSqGSIb3DQEBAQUA
|
||||||
|
A4IBDwAwggEKAoIBAQC9q+slYWncCXZXBGArH7hjaZtFG+jG/J3anI3TEwn+0Imx
|
||||||
|
xobyzrS/pZn0VwI54yRIjYNeyTjPultB1CfSHYYOv/kw4mQ8BVZJYQ3jq2lotne/
|
||||||
|
TOnzxkhucSTUbQ+x0W5b+mcuxqQ+UAyuXVUCsWxXpixq0u3fRQhhhxE73tK2Sg56
|
||||||
|
ELEDnD5eq18dl5BnT8NLzXrfeDBhRwy5JNQVnrSvuB7X+bvsNNIqDetNWTmx5s/x
|
||||||
|
yNL5pYe/E/8bK+8OxP7eCNEnHb/k7cmR8fTNo6xpTYC+PQ9HRzmuHKes07+XWT4Y
|
||||||
|
kkFxsGsz7IDw5/OnihdSsJ9oirdG4vc936SFwqyLAgMBAAGjUDBOMB0GA1UdDgQW
|
||||||
|
BBRaSF1L+ivPhmIVGQjtviBqZWDS9DAfBgNVHSMEGDAWgBRaSF1L+ivPhmIVGQjt
|
||||||
|
viBqZWDS9DAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBQUAA4IBAQCjrgB9+Zuq
|
||||||
|
Rx7T2mRUl4jf75dLabuBQD0ePALTtvNyBSghhzSr90mE7GlFOYAv0JsmEa3R1LVF
|
||||||
|
wLPIdrIhNHpt7hN0PkhUlfgmxBnRSCfhpiq4xxsDVFM7ehtDz4+dv1LUDMXo07+E
|
||||||
|
f24g9aqmypiFzHisUQrYIhtQmHxRpKyGp6kDAW9qNxg6k/Um00aHdYfuD9ER4ksR
|
||||||
|
f8Hto7f+vssKxCRY2OZXqq13PxEwC5+hgAUkTdrycA/moXFuHJi3lCnCND7sSzvG
|
||||||
|
tXBggOusyFZFC4bs2m+V+Z+RN+tK2c/c0nq5HR8MV5HwIm4Z8GoT2/0BfJ00cgWL
|
||||||
|
lVz0gDBfdH8f
|
||||||
|
-----END CERTIFICATE-----
|
||||||
|
nginx_custom_http:
|
||||||
|
- 'add_header X-ansible 1;'
|
||||||
|
- 'geoip_country {% if ansible_distribution == "Debian" %}/usr/share/GeoIP/GeoIP.dat{% else %}/usr/local/share/GeoIP/GeoIP.dat{% endif %};'
|
||||||
|
- 'map $geoip_country_code $allowed_country {'
|
||||||
|
- ' default yes;'
|
||||||
|
- ' MA no;'
|
||||||
|
- ' DZ no;'
|
||||||
|
- ' TN no;'
|
||||||
|
- '}'
|
||||||
|
nginx_default_site: 'first-test'
|
||||||
|
nginx_default_site_ssl: 'test-ssl-predeployed.local'
|
||||||
|
nginx_sites:
|
||||||
- name:
|
- name:
|
||||||
- 'test.local'
|
- 'test.local'
|
||||||
- '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: true
|
||||||
more:
|
more:
|
||||||
- 'autoindex off;'
|
- 'autoindex off;'
|
||||||
location:
|
location:
|
||||||
@@ -30,49 +158,378 @@
|
|||||||
- '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'
|
||||||
|
template: '_base'
|
||||||
|
location:
|
||||||
|
'/hello':
|
||||||
|
- htpasswd: 'hello'
|
||||||
|
'/public':
|
||||||
|
- htpasswd: false
|
||||||
|
use_error_log: true
|
||||||
|
- name: 'test-htpasswd-all.local'
|
||||||
|
template: '_base'
|
||||||
|
htpasswd: 'hello'
|
||||||
- name: 'test-location.local'
|
- name: 'test-location.local'
|
||||||
template: '_base'
|
template: '_base'
|
||||||
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: "{{ nginx_php.1.version if nginx_php.1 is defined else nginx_php.0.version }}"
|
||||||
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-php-index2.local'
|
||||||
|
template: '_php_index2'
|
||||||
- name: 'test-proxy.local'
|
- name: 'test-proxy.local'
|
||||||
listen:
|
listen:
|
||||||
- 8080
|
- 8080
|
||||||
template: '_proxy'
|
template: '_proxy'
|
||||||
upstream_name: 'test'
|
upstream_name: 'test'
|
||||||
|
headers:
|
||||||
|
'X-proxyfied': '1'
|
||||||
- name: 'deleted.local'
|
- name: 'deleted.local'
|
||||||
delete: true
|
state: 'absent'
|
||||||
|
- name: 'redirect-to.local'
|
||||||
|
redirect_to: 'http://test.local'
|
||||||
|
- name: 'backuppc.local'
|
||||||
|
template: '_backuppc'
|
||||||
|
htpasswd: 'hello'
|
||||||
|
- name: 'nagios3.local'
|
||||||
|
template: '_nagios3'
|
||||||
|
htpasswd: 'nagios'
|
||||||
|
- name: 'test-ssl.local'
|
||||||
|
proto: ['http', 'https']
|
||||||
|
template: '_base'
|
||||||
|
- name: 'test-ssl-predeployed.local'
|
||||||
|
proto: ['http', 'https']
|
||||||
|
template: '_base'
|
||||||
|
ssl_name: 'test-ssl-predeployed.local'
|
||||||
|
headers:
|
||||||
|
'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:
|
||||||
|
- 'test-ssl-redirect-many.local'
|
||||||
|
- 'test-ssl-redirect-many2.local'
|
||||||
|
listen_ssl: [8443]
|
||||||
|
proto: ['https']
|
||||||
|
template: '_base'
|
||||||
|
ssl_name: 'test-ssl.local'
|
||||||
|
redirect_https: true
|
||||||
|
redirect_from:
|
||||||
|
- 'www.test-ssl-redirect-many.local'
|
||||||
|
- 'www.test-ssl-redirect-many2.local'
|
||||||
|
- 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'
|
||||||
|
- name: '{{ ngrok.stdout }}'
|
||||||
|
proto: ['http', 'https']
|
||||||
|
template: '_base'
|
||||||
|
ssl_name: '{{ ngrok.stdout }}'
|
||||||
|
headers:
|
||||||
|
'X-acme': '1'
|
||||||
|
nginx_dh_length: 1024
|
||||||
roles:
|
roles:
|
||||||
- ../../
|
- ../../
|
||||||
post_tasks:
|
post_tasks:
|
||||||
|
# --------------------------------
|
||||||
|
# Apps
|
||||||
|
# --------------------------------
|
||||||
|
- name: INCLUDE | Post_tasks related to OS version
|
||||||
|
include: "includes/post_{{ ansible_distribution }}.yml"
|
||||||
|
|
||||||
|
# --------------------------------
|
||||||
|
# Deploy index files
|
||||||
|
# --------------------------------
|
||||||
- name: -- Add PHP file --
|
- name: -- Add PHP file --
|
||||||
copy: dest="{{ nginx_root }}/{{ item }}/public/index.php" content="<?php phpinfo();"
|
copy:
|
||||||
with_items: ['test-php.local', 'test-php-index.local']
|
dest: "{{ nginx_root }}/{{ item }}/public/index.php"
|
||||||
|
content: "<?php phpinfo();"
|
||||||
|
with_items:
|
||||||
|
- 'test-php.local'
|
||||||
|
- 'test-php-index.local'
|
||||||
|
- 'test-php-index2.local'
|
||||||
|
|
||||||
- name: -- Add HTML file --
|
- name: -- Add HTML file --
|
||||||
copy: dest="{{ item }}/index.html" content="Index HTML test OK\n"
|
copy:
|
||||||
with_items: ['{{ nginx_root }}/test.local/public', '/var/tmp']
|
dest: "{{ item }}/index.html"
|
||||||
- name: -- VERIFY VHOSTS --
|
content: "Index HTML test OK\n"
|
||||||
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:
|
||||||
with_items: nginx_vhosts
|
- '{{ nginx_root }}/first-test/public'
|
||||||
when: item.delete is undefined or not item.delete
|
- '/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'
|
||||||
|
- '{{ nginx_root }}/{{ ngrok.stdout }}/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"
|
||||||
|
|
||||||
|
# --------------------------------
|
||||||
|
# Test custom facts
|
||||||
|
# --------------------------------
|
||||||
|
- name: -- CHECK FACTS --
|
||||||
|
assert:
|
||||||
|
that: "'{{ ansible_local.nginx.fact_nginx_sites[0].name[0] }}' == 'test.local'"
|
||||||
|
# --------------------------------
|
||||||
|
# Simple sites tests
|
||||||
|
# --------------------------------
|
||||||
|
- name: -- VERIFY SITES --
|
||||||
|
uri:
|
||||||
|
url: "http://{{ item | nginx_site_name }}{% if item.listen is defined %}:{{ item.listen[0] }}{% endif %}/"
|
||||||
|
status_code: '200,301,302,401,403'
|
||||||
|
follow_redirects: none
|
||||||
|
with_items: "{{ nginx_sites }}"
|
||||||
|
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"
|
uri:
|
||||||
register: f
|
url: "http://test-php-index.local/phpinfo.php"
|
||||||
failed_when: f.stdout.find('403 Forbidden') == -1
|
status_code: 403
|
||||||
|
|
||||||
|
- name: -- VERIFY REDIRECT SITES --
|
||||||
|
uri:
|
||||||
|
url: "http://{{ item.redirect_from[0] }}/"
|
||||||
|
status_code: 301
|
||||||
|
follow_redirects: none
|
||||||
|
with_items: "{{ nginx_sites }}"
|
||||||
|
when: item.redirect_from is defined and (item.state is undefined or item.state != "absent") and (item.proto is not defined or 'https' not in item.proto)
|
||||||
changed_when: false
|
changed_when: false
|
||||||
- name: -- VERIFY REDIRECT VHOSTS --
|
|
||||||
command: "curl -H 'Host: {{ item.redirect_from[0] }}' http://127.0.0.1/"
|
- name: -- VERIFY REDIRECT HTTPS SITES --
|
||||||
with_items: nginx_vhosts
|
uri:
|
||||||
when: item.redirect_from is defined and (item.delete is undefined or not item.delete)
|
url: "https://{{ item.redirect_from[0] }}:{{ item.listen_ssl[0] | default(443) }}/"
|
||||||
|
status_code: 301
|
||||||
|
follow_redirects: none
|
||||||
|
validate_certs: no
|
||||||
|
with_items: "{{ nginx_sites }}"
|
||||||
|
when: item.redirect_from is defined and (item.state is undefined or item.state != "absent") and item.proto is defined and 'https' in item.proto
|
||||||
changed_when: false
|
changed_when: false
|
||||||
register: r
|
|
||||||
failed_when: r.stdout.find('301 Moved Permanently') == -1
|
# --------------------------------
|
||||||
|
# PHP
|
||||||
|
# --------------------------------
|
||||||
|
- name: -- VERIFY PHP SITES --
|
||||||
|
uri:
|
||||||
|
url: "http://{{ item.name}}/"
|
||||||
|
return_content: yes
|
||||||
|
register: p
|
||||||
|
with_items: "{{ nginx_sites }}"
|
||||||
|
when: >
|
||||||
|
item.template is defined and
|
||||||
|
(item.template == '_php' or item.template == '_php_index' or item.template == '_php_index2')
|
||||||
|
failed_when: p.content.find('PHP Version ' + item.php_version if 'php_version' in item else nginx_php.0.version) == -1
|
||||||
|
|
||||||
|
- name: -- VERIFY INDEX2 --
|
||||||
|
uri:
|
||||||
|
url: "http://test-php-index2.local/lorem.php?ipsum=sit&dolor=amet"
|
||||||
|
return_content: yes
|
||||||
|
register: p2
|
||||||
|
failed_when: p2.content.find('PHP Version') == -1
|
||||||
|
|
||||||
|
# --------------------------------
|
||||||
|
# Basic Auth
|
||||||
|
# --------------------------------
|
||||||
|
- name: -- VERIFY AUTH BASIC NONE --
|
||||||
|
uri:
|
||||||
|
url: "http://test-htpasswd.local/hello/"
|
||||||
|
status_code: 401
|
||||||
|
|
||||||
|
- name: -- VERIFY AUTH BASIC FAIL --
|
||||||
|
uri:
|
||||||
|
url: "http://test-htpasswd.local/hello/"
|
||||||
|
status_code: 401
|
||||||
|
user: "fail"
|
||||||
|
password: "fail"
|
||||||
|
force_basic_auth: yes
|
||||||
|
|
||||||
|
- name: -- VERIFY AUTH BASIC OK --
|
||||||
|
uri:
|
||||||
|
url: "http://test-htpasswd.local/hello/"
|
||||||
|
user: "hanx"
|
||||||
|
password: "qwerty"
|
||||||
|
force_basic_auth: yes
|
||||||
|
|
||||||
|
- name: -- VERIFY AUTH BASIC FAIL GLOBAL --
|
||||||
|
uri:
|
||||||
|
url: "http://test-htpasswd-all.local/"
|
||||||
|
status_code: 401
|
||||||
|
user: "fail"
|
||||||
|
password: "fail"
|
||||||
|
force_basic_auth: yes
|
||||||
|
|
||||||
|
- name: -- VERIFY AUTH BASIC OK GLOBAL --
|
||||||
|
uri:
|
||||||
|
url: "http://test-htpasswd-all.local/"
|
||||||
|
user: "hanx"
|
||||||
|
password: "qwerty"
|
||||||
|
force_basic_auth: yes
|
||||||
|
|
||||||
|
# --------------------------------
|
||||||
|
# BackupPC
|
||||||
|
# --------------------------------
|
||||||
|
- name: -- VERIFY BACKUPPC --
|
||||||
|
uri:
|
||||||
|
url: "http://backuppc.local/"
|
||||||
|
user: "hanx"
|
||||||
|
password: "qwerty"
|
||||||
|
force_basic_auth: yes
|
||||||
|
return_content: yes
|
||||||
|
register: authbpc
|
||||||
|
when: ansible_distribution != 'FreeBSD'
|
||||||
|
failed_when: authbpc.content.find('BackupPC Server Status') == -1
|
||||||
|
|
||||||
|
# --------------------------------
|
||||||
|
# Nagios (not avaiblable on Debian >= 9 and not tested on FreeBSD)
|
||||||
|
# --------------------------------
|
||||||
|
- block:
|
||||||
|
|
||||||
|
- name: -- VERIFY NAGIOS3 PHP --
|
||||||
|
uri:
|
||||||
|
url: "http://nagios3.local/side.php"
|
||||||
|
user: "nagiosadmin"
|
||||||
|
password: "nagios"
|
||||||
|
force_basic_auth: yes
|
||||||
|
return_content: yes
|
||||||
|
register: nagios_php
|
||||||
|
failed_when: nagios_php.content.find('Nagios Core') == -1
|
||||||
|
|
||||||
|
- name: -- VERIFY NAGIOS3 CGI --
|
||||||
|
uri:
|
||||||
|
url: "http://nagios3.local/cgi-bin{% if ansible_distribution == 'Debian' %}/nagios3{% endif %}/summary.cgi"
|
||||||
|
user: "nagiosadmin"
|
||||||
|
password: "nagios"
|
||||||
|
force_basic_auth: yes
|
||||||
|
return_content: yes
|
||||||
|
register: nagios_cgi
|
||||||
|
failed_when: nagios_cgi.content.find('Nagios Event Summary') == -1
|
||||||
|
|
||||||
|
when: ansible_distribution == 'Debian' and ansible_distribution_major_version | version_compare('9', 'lt')
|
||||||
|
|
||||||
|
# --------------------------------
|
||||||
|
# SSL
|
||||||
|
# --------------------------------
|
||||||
|
- name: -- VERIFY SSL --
|
||||||
|
uri:
|
||||||
|
url: "https://{{ item }}/"
|
||||||
|
return_content: yes
|
||||||
|
validate_certs: no
|
||||||
|
register: sslok
|
||||||
|
failed_when: sslok.content.find('Index HTML test OK') == -1
|
||||||
|
with_items:
|
||||||
|
- 'test-ssl-predeployed.local'
|
||||||
|
- 'test-ssl.local'
|
||||||
|
- '{{ ngrok.stdout }}'
|
||||||
|
|
||||||
|
- name: -- VERIFY SSL REDIRECT --
|
||||||
|
uri:
|
||||||
|
url: "http://{{ item.name }}/"
|
||||||
|
validate_certs: no
|
||||||
|
status_code: 301
|
||||||
|
return_content: yes
|
||||||
|
follow_redirects: none
|
||||||
|
register: sslredirok
|
||||||
|
failed_when: '"https://%s%s" % (item.name, ":" + item.port if item.port is defined else "") not in sslredirok.location'
|
||||||
|
with_items:
|
||||||
|
- name: 'test-ssl-redirect.local'
|
||||||
|
- name: 'test-ssl-redirect-many.local'
|
||||||
|
port: '8443'
|
||||||
|
- name: 'test-ssl-redirect-many2.local'
|
||||||
|
port: '8443'
|
||||||
|
|
||||||
|
# --------------------------------
|
||||||
|
# Default sites
|
||||||
|
# --------------------------------
|
||||||
|
- name: -- VERIFY DEFAULT SITE --
|
||||||
|
uri:
|
||||||
|
url: 'http://127.0.0.1/'
|
||||||
|
return_content: yes
|
||||||
|
register: vdefault
|
||||||
|
failed_when: >
|
||||||
|
vdefault.content.find('Index HTML test OK') == -1 or
|
||||||
|
vdefault.x_ansible_default is not defined
|
||||||
|
|
||||||
|
- name: -- VERIFY DEFAULT SITE + STUB STATUS--
|
||||||
|
uri:
|
||||||
|
url: 'http://127.0.0.1/status'
|
||||||
|
return_content: yes
|
||||||
|
register: vdefault_status
|
||||||
|
failed_when: >
|
||||||
|
vdefault_status.content.find('Active connections') == -1 or
|
||||||
|
vdefault_status.x_ansible_default is not defined
|
||||||
|
|
||||||
|
- name: -- VERIFY DEFAULT SSL SITE --
|
||||||
|
uri:
|
||||||
|
url: 'https://127.0.0.1/'
|
||||||
|
return_content: yes
|
||||||
|
validate_certs: no
|
||||||
|
register: vdefault
|
||||||
|
failed_when: >
|
||||||
|
vdefault.content.find('Index HTML test OK') == -1 or
|
||||||
|
vdefault.x_ansible_default is not defined
|
||||||
|
|
||||||
|
- name: -- VERIFY NOT DEFAULT SITE --
|
||||||
|
uri:
|
||||||
|
url: 'http://test-php.local/'
|
||||||
|
return_content: yes
|
||||||
|
register: vphp
|
||||||
|
failed_when: vphp.x_ansible_default is defined
|
||||||
|
|
||||||
|
- name: -- VERIFY NOT DEFAULT SSL SITE --
|
||||||
|
uri:
|
||||||
|
url: 'https://test-ssl.local/'
|
||||||
|
return_content: yes
|
||||||
|
validate_certs: no
|
||||||
|
register: notdefaultssl
|
||||||
|
failed_when: notdefaultssl.x_ansible_default is defined
|
||||||
|
|
||||||
|
# --------------------------------
|
||||||
|
# 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
8
vars/Debian.yml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
nginx_events_use: 'epoll'
|
||||||
|
nginx_pid: '/run/nginx.pid'
|
||||||
|
nginx_etc_dir: '/etc/nginx'
|
||||||
|
|
||||||
|
# Specific sites
|
||||||
|
nginx_nagios_root: '/usr/share/nagios3/htdocs'
|
||||||
|
nginx_nagios_stylesheets: '/etc/nagios3/stylesheets'
|
||||||
|
nginx_fcgiwrap_sock: '/var/run/fcgiwrap.socket'
|
||||||
9
vars/FreeBSD.yml
Normal file
9
vars/FreeBSD.yml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
nginx_events_use: 'kqueue'
|
||||||
|
nginx_pid: '/var/run/nginx.pid'
|
||||||
|
nginx_etc_dir: '/usr/local/etc/nginx'
|
||||||
|
|
||||||
|
# Specific sites
|
||||||
|
nginx_nagios_root: '/usr/local/www/nagios'
|
||||||
|
nginx_fcgiwrap_sock: '/var/run/fcgiwrap/fcgiwrap.sock'
|
||||||
|
|
||||||
|
nginx_acmesh_bin: '/usr/local/sbin/acme.sh'
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
nginx_dh_path: /etc/nginx/ssl/dhparams.pem
|
|
||||||
|
|
||||||
nginx_upstream_server_params:
|
nginx_upstream_server_params:
|
||||||
- key: 'weight'
|
- key: 'weight'
|
||||||
default: 1
|
default: 1
|
||||||
@@ -23,3 +21,32 @@ nginx_upstream_server_params:
|
|||||||
# - key: 'resolve'
|
# - key: 'resolve'
|
||||||
# is_bool: true
|
# is_bool: true
|
||||||
# min_version: '1.5.12'
|
# min_version: '1.5.12'
|
||||||
|
|
||||||
|
nginx_dirs:
|
||||||
|
- dir: "{{ nginx_htpasswd_dir }}"
|
||||||
|
mode: "0750"
|
||||||
|
owner: "{{ nginx_user }}"
|
||||||
|
- dir: "{{ nginx_ssl_dir }}"
|
||||||
|
mode: "0750"
|
||||||
|
owner: "root"
|
||||||
|
- dir: "{{ nginx_helper_dir }}"
|
||||||
|
mode: "0755"
|
||||||
|
owner: "root"
|
||||||
|
- dir: "{{ nginx_etc_dir }}/modules-available"
|
||||||
|
mode: "0755"
|
||||||
|
owner: "root"
|
||||||
|
- dir: "{{ nginx_etc_dir }}/modules-enabled"
|
||||||
|
mode: "0755"
|
||||||
|
owner: "root"
|
||||||
|
|
||||||
|
nginx_templates_no_dir:
|
||||||
|
- '_backuppc'
|
||||||
|
- '_nagios3'
|
||||||
|
- '_proxy'
|
||||||
|
|
||||||
|
nginx_servers_default_headers:
|
||||||
|
'X-Frame-Options': 'DENY always'
|
||||||
|
'X-Content-Type-Options': 'nosniff always'
|
||||||
|
'X-XSS-Protection': '1; mode=block'
|
||||||
|
|
||||||
|
nginx_acmesh_bin: "{{ nginx_acmesh_dir }}/acme.sh"
|
||||||
|
|||||||
Reference in New Issue
Block a user