mirror of
https://github.com/HanXHX/ansible-nginx.git
synced 2026-02-28 09:22:10 +07:00
Compare commits
70 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5e2f988beb | ||
|
|
6aea2bcb5f | ||
|
|
8c6c4dc813 | ||
|
|
a2780d3d95 | ||
|
|
6c7e0c2a47 | ||
|
|
bdddb06fcc | ||
|
|
6e5fce00e7 | ||
|
|
8268eb266a | ||
|
|
8b73a835c6 | ||
|
|
40ebe61c57 | ||
|
|
0f8688f290 | ||
|
|
204e95725e | ||
|
|
da08953a27 | ||
|
|
4c63efa588 | ||
|
|
3e228d0812 | ||
|
|
1e7a0fc855 | ||
|
|
93b90c748f | ||
|
|
d8f6088362 | ||
|
|
8c3b1c7f13 | ||
|
|
5cdd1a8b37 | ||
|
|
0363a37e06 | ||
|
|
a1e76453cf | ||
|
|
729173c46c | ||
|
|
2f8ce00067 | ||
|
|
9b286f9b96 | ||
|
|
4a2478a4fb | ||
|
|
a9a72dd25f | ||
|
|
2a612a55b9 | ||
|
|
1280a441ee | ||
|
|
21edb6b584 | ||
|
|
c524b97b0f | ||
|
|
993310641a | ||
|
|
f5885c5c55 | ||
|
|
bb5e00d6f5 | ||
|
|
cf010e4a4b | ||
|
|
39d3f5f06a | ||
|
|
247f849b86 | ||
|
|
a03a656b18 | ||
|
|
1239219d90 | ||
|
|
4f94fc2211 | ||
|
|
e89a154bb5 | ||
|
|
c9bda9e95a | ||
|
|
4efc975770 | ||
|
|
20d04015c1 | ||
|
|
98b0de9265 | ||
|
|
95706359c8 | ||
|
|
1437619475 | ||
|
|
7959182bf8 | ||
|
|
5ed17149e5 | ||
|
|
91ca31e676 | ||
|
|
a021888728 | ||
|
|
c12113921c | ||
|
|
74b48fca2c | ||
|
|
3642df1d5f | ||
|
|
c399bf35b5 | ||
|
|
8218e5c972 | ||
|
|
87c1c68949 | ||
|
|
817929beca | ||
|
|
678dff9a1a | ||
|
|
3da65983bd | ||
|
|
3fb8f092fb | ||
|
|
19a85ca381 | ||
|
|
2bab49221a | ||
|
|
6e877c070e | ||
|
|
c165f88126 | ||
|
|
59dd3997de | ||
|
|
ae6dc88bc4 | ||
|
|
6719b415ab | ||
|
|
fd21603a4d | ||
|
|
f52be2bbf3 |
2
.ansible-lint
Normal file
2
.ansible-lint
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
enable_list:
|
||||||
|
- fqcn-builtins
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@
|
|||||||
*.swp
|
*.swp
|
||||||
*.retry
|
*.retry
|
||||||
*.pyc
|
*.pyc
|
||||||
|
/tests/HanXHX.php
|
||||||
|
|||||||
63
.travis.yml
63
.travis.yml
@@ -1,48 +1,35 @@
|
|||||||
|
---
|
||||||
|
|
||||||
env:
|
env:
|
||||||
- PLATFORM='docker-debian-jessie' ANSIBLE_VERSION='ansible>=2.2,<2.3'
|
global:
|
||||||
- PLATFORM='docker-debian-jessie-backports' ANSIBLE_VERSION='ansible>=2.2,<2.3'
|
- VAGRANT_VERSION='2.2.18'
|
||||||
- PLATFORM='docker-debian-jessie-dotdeb' ANSIBLE_VERSION='ansible>=2.2,<2.3'
|
jobs:
|
||||||
- PLATFORM='docker-debian-jessie' ANSIBLE_VERSION='ansible>=2.3,<2.4'
|
- PLATFORM='docker-debian-stretch' ANSIBLE_VERSION='>=2.11,<2.12'
|
||||||
- PLATFORM='docker-debian-jessie-backports' ANSIBLE_VERSION='ansible>=2.3,<2.4'
|
- PLATFORM='docker-debian-bullseye' ANSIBLE_VERSION='>=2.11,<2.12'
|
||||||
- PLATFORM='docker-debian-jessie-dotdeb' ANSIBLE_VERSION='ansible>=2.3,<2.4'
|
- PLATFORM='docker-debian-buster' ANSIBLE_VERSION='>=2.11,<2.12'
|
||||||
- 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:
|
os:
|
||||||
allow_failures:
|
- linux
|
||||||
- env: PLATFORM='docker-debian-jessie' ANSIBLE_VERSION='ansible>=2.5b,<2.6'
|
dist: focal
|
||||||
- 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
|
|
||||||
|
|
||||||
dist: trusty
|
|
||||||
|
|
||||||
language: python
|
language: python
|
||||||
|
python:
|
||||||
|
- 3.8
|
||||||
|
|
||||||
services:
|
services:
|
||||||
- docker
|
- docker
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
- wget https://releases.hashicorp.com/vagrant/2.0.1/vagrant_2.0.1_x86_64.deb
|
- sudo apt-get -q update
|
||||||
- sudo dpkg -i vagrant_2.0.1_x86_64.deb
|
- sudo apt-get install -y yamllint
|
||||||
|
- sudo wget -nv https://releases.hashicorp.com/vagrant/${VAGRANT_VERSION}/vagrant_${VAGRANT_VERSION}_x86_64.deb
|
||||||
|
- sudo dpkg -i vagrant_${VAGRANT_VERSION}_x86_64.deb
|
||||||
|
|
||||||
install:
|
install:
|
||||||
- pip install "$ANSIBLE_VERSION"
|
- sudo pip install "ansible-core$ANSIBLE_VERSION"
|
||||||
|
- sudo pip install ansible-lint
|
||||||
|
- ansible-galaxy collection install community.general
|
||||||
|
- ansible-galaxy install -p ./tests HanXHX.php
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- VAGRANT_DEFAULT_PROVIDER=docker vagrant up $PLATFORM
|
- VAGRANT_DEFAULT_PROVIDER=docker vagrant up $PLATFORM
|
||||||
@@ -52,6 +39,14 @@ script:
|
|||||||
&& (echo 'Idempotence test: pass' && exit 0)
|
&& (echo 'Idempotence test: pass' && exit 0)
|
||||||
|| (echo 'Idempotence test: fail' && exit 1)
|
|| (echo 'Idempotence test: fail' && exit 1)
|
||||||
- VAGRANT_DEFAULT_PROVIDER=docker vagrant status
|
- VAGRANT_DEFAULT_PROVIDER=docker vagrant status
|
||||||
|
- >
|
||||||
|
yamllint .
|
||||||
|
&& (echo 'YAML lint test: pass' && exit 0)
|
||||||
|
|| (echo 'YAML lint test: fail' && exit 1)
|
||||||
|
- >
|
||||||
|
ansible-lint -v tests/test.yml
|
||||||
|
&& (echo 'Ansible lint test: pass' && exit 0)
|
||||||
|
|| (echo 'Ansible lint test: fail' && exit 1)
|
||||||
|
|
||||||
notifications:
|
notifications:
|
||||||
webhooks: https://galaxy.ansible.com/api/v1/notifications/
|
webhooks: https://galaxy.ansible.com/api/v1/notifications/
|
||||||
|
|||||||
6
.yamllint.yml
Normal file
6
.yamllint.yml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
extends: default
|
||||||
|
|
||||||
|
rules:
|
||||||
|
line-length: disable
|
||||||
23
README.md
23
README.md
@@ -1,7 +1,7 @@
|
|||||||
Nginx for Debian/FreeBSD Ansible role
|
Nginx for Debian/FreeBSD Ansible role
|
||||||
=====================================
|
=====================================
|
||||||
|
|
||||||
[](https://galaxy.ansible.com/HanXHX/nginx/) [](https://travis-ci.org/HanXHX/ansible-nginx)
|
[](https://galaxy.ansible.com/HanXHX/nginx/) [](https://app.travis-ci.com/HanXHX/ansible-nginx)
|
||||||
|
|
||||||
Install and configure Nginx on Debian/FreeBSD.
|
Install and configure Nginx on Debian/FreeBSD.
|
||||||
|
|
||||||
@@ -21,16 +21,19 @@ Features:
|
|||||||
Supported OS:
|
Supported OS:
|
||||||
|
|
||||||
| OS | Working | Stable (active support) |
|
| OS | Working | Stable (active support) |
|
||||||
| ------------------ | ------- | ----------------------- |
|
| -------------------- | ------- | ----------------------- |
|
||||||
| Debian Jessie (8) | Yes | Yes |
|
| Debian Jessie (8) | Yes | Check latest supported version ([1.5.0](https://github.com/HanXHX/ansible-nginx/releases/tag/1.5.0)) |
|
||||||
| Debian Stretch (9) | Yes | Yes |
|
| Debian Stretch (9) | Yes | Yes |
|
||||||
|
| Debian Buster (10) | Yes | Yes |
|
||||||
|
| Debian Bullseye (11) | Yes | Yes |
|
||||||
| FreeBSD 11 | Yes | No |
|
| FreeBSD 11 | Yes | No |
|
||||||
| FreeBSD 12 | Yes | No |
|
| FreeBSD 12 | Yes | No |
|
||||||
|
|
||||||
Requirements
|
Requirements
|
||||||
------------
|
------------
|
||||||
|
|
||||||
None. If you set true to `nginx_backports`, you must install backports repository before lauching this role.
|
- Ansible >=2.11
|
||||||
|
- If you set true to `nginx_backports`, you must install backports repository before lauching this role.
|
||||||
|
|
||||||
Role Variables
|
Role Variables
|
||||||
--------------
|
--------------
|
||||||
@@ -54,6 +57,7 @@ FreeBSD:
|
|||||||
- `nginx_error_log_level`: default log level
|
- `nginx_error_log_level`: default log level
|
||||||
- `nginx_auto_config_httpv2`: boolean, auto configure HTTP2 where possible
|
- `nginx_auto_config_httpv2`: boolean, auto configure HTTP2 where possible
|
||||||
- `nginx_fastcgi_fix_realpath`: boolean, use realpath for fastcgi (fix problems with symlinks and PHP opcache)
|
- `nginx_fastcgi_fix_realpath`: boolean, use realpath for fastcgi (fix problems with symlinks and PHP opcache)
|
||||||
|
- `nginx_default_hsts`: string, default header sent for HSTS
|
||||||
|
|
||||||
### Nginx Configuration
|
### Nginx Configuration
|
||||||
|
|
||||||
@@ -97,13 +101,22 @@ Note
|
|||||||
|
|
||||||
- Active support for Debian.
|
- Active support for Debian.
|
||||||
- FreeBSD support is experimental (no Travis). I only test (for the moment) 10.2 (but it can work on other versions).
|
- FreeBSD support is experimental (no Travis). I only test (for the moment) 10.2 (but it can work on other versions).
|
||||||
- I don't manage BackupPC for FreeBSD (PR welcome).
|
|
||||||
|
|
||||||
Dependencies
|
Dependencies
|
||||||
------------
|
------------
|
||||||
|
|
||||||
None
|
None
|
||||||
|
|
||||||
|
|
||||||
|
If you need to dev this role locally
|
||||||
|
------------------------------------
|
||||||
|
|
||||||
|
Before use vagrant, run once:
|
||||||
|
|
||||||
|
```
|
||||||
|
ansible-galaxy install -p ./tests/ HanXHX.php,master
|
||||||
|
```
|
||||||
|
|
||||||
Example Playbook
|
Example Playbook
|
||||||
----------------
|
----------------
|
||||||
|
|
||||||
|
|||||||
34
Vagrantfile
vendored
34
Vagrantfile
vendored
@@ -6,24 +6,20 @@
|
|||||||
Vagrant.configure("2") do |config|
|
Vagrant.configure("2") do |config|
|
||||||
|
|
||||||
vms_debian = [
|
vms_debian = [
|
||||||
{ :name => "debian-jessie", :box => "debian/jessie64", :vars => { "nginx_php": [{"version": "5.6"}] }},
|
{ :name => "debian-stretch", :box => "debian/stretch64", :vars => {} },
|
||||||
{ :name => "debian-jessie-backports", :box => "debian/jessie64", :vars => { "nginx_php": [{"version": "5.6"}], "nginx_backports": true }},
|
{ :name => "debian-buster", :box => "debian/buster64", :vars => {} },
|
||||||
{ :name => "debian-jessie-dotdeb", :box => "debian/jessie64", :vars => { "nginx_php": [{"version": "7.0"}, {"version": "5.6", "upstream_name": "legacy"} ], "dotdeb": true }},
|
{ :name => "debian-bullseye", :box => "debian/bullseye64", :vars => {} }
|
||||||
{ :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 }}
|
|
||||||
]
|
]
|
||||||
|
|
||||||
vms_freebsd = [
|
vms_freebsd = [
|
||||||
{ :name => "freebsd-11", :box => "freebsd/FreeBSD-11.1-STABLE", :vars => {} },
|
{ :name => "freebsd-11", :box => "freebsd/FreeBSD-11.3-STABLE", :vars => {} },
|
||||||
{ :name => "freebsd-12", :box => "freebsd/FreeBSD-12.0-CURRENT", :vars => {} }
|
{ :name => "freebsd-12", :box => "freebsd/FreeBSD-12.1-STABLE", :vars => {} }
|
||||||
]
|
]
|
||||||
|
|
||||||
conts = [
|
conts = [
|
||||||
{ :name => "docker-debian-jessie", :docker => "hanxhx/vagrant-ansible:debian8", :vars => { "nginx_php" => [{"version" => "5.6"}] }},
|
{ :name => "docker-debian-stretch", :docker => "hanxhx/vagrant-ansible:debian9", :vars => {} },
|
||||||
{ :name => "docker-debian-jessie-backports", :docker => "hanxhx/vagrant-ansible:debian8", :vars => { "nginx_php": [{"version": "5.6"}], "nginx_backports": true }},
|
{ :name => "docker-debian-buster", :docker => "hanxhx/vagrant-ansible:debian10", :vars => {} },
|
||||||
{ :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-bullseye", :docker => "hanxhx/vagrant-ansible:debian11", :vars => {} },
|
||||||
{ :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.network "private_network", type: "dhcp"
|
||||||
@@ -36,11 +32,16 @@ Vagrant.configure("2") do |config|
|
|||||||
d.remains_running = true
|
d.remains_running = true
|
||||||
d.has_ssh = true
|
d.has_ssh = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if opts[:name].include? "bullseye"
|
||||||
|
m.vm.provision "shell", inline: "[ -f '/root/first_provision' ] || (apt-get update -qq && apt-get -y dist-upgrade && touch /root/first_provision)"
|
||||||
|
end
|
||||||
|
|
||||||
m.vm.provision "ansible" do |ansible|
|
m.vm.provision "ansible" do |ansible|
|
||||||
ansible.playbook = "tests/test.yml"
|
ansible.playbook = "tests/test.yml"
|
||||||
ansible.verbose = 'vv'
|
ansible.verbose = 'vv'
|
||||||
ansible.become = true
|
ansible.become = true
|
||||||
ansible.extra_vars = opts[:vars].merge({ "nginx_debug_role": true })
|
ansible.extra_vars = opts[:vars].merge({ "nginx_debug_role": true, is_docker: true })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -52,6 +53,11 @@ Vagrant.configure("2") do |config|
|
|||||||
v.cpus = 1
|
v.cpus = 1
|
||||||
v.memory = 256
|
v.memory = 256
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if opts[:name].include? "bullseye"
|
||||||
|
m.vm.provision "shell", inline: "[ -f '/root/first_provision' ] || (apt-get update -qq && apt-get -y dist-upgrade && touch /root/first_provision)"
|
||||||
|
end
|
||||||
|
|
||||||
m.vm.provision "ansible" do |ansible|
|
m.vm.provision "ansible" do |ansible|
|
||||||
ansible.playbook = "tests/test.yml"
|
ansible.playbook = "tests/test.yml"
|
||||||
ansible.verbose = 'vv'
|
ansible.verbose = 'vv'
|
||||||
@@ -70,7 +76,7 @@ Vagrant.configure("2") do |config|
|
|||||||
v.cpus = 2
|
v.cpus = 2
|
||||||
v.memory = 512
|
v.memory = 512
|
||||||
end
|
end
|
||||||
m.vm.provision "shell", inline: "pkg install -y python bash"
|
m.vm.provision "shell", inline: "[ -e /usr/local/bin/bash ] || pkg install -y python bash"
|
||||||
m.vm.provision "ansible" do |ansible|
|
m.vm.provision "ansible" do |ansible|
|
||||||
ansible.playbook = "tests/test.yml"
|
ansible.playbook = "tests/test.yml"
|
||||||
ansible.verbose = 'vv'
|
ansible.verbose = 'vv'
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ nginx_auto_config_httpv2: true
|
|||||||
nginx_default_site: null
|
nginx_default_site: null
|
||||||
nginx_default_site_ssl: null
|
nginx_default_site_ssl: null
|
||||||
nginx_fastcgi_fix_realpath: true
|
nginx_fastcgi_fix_realpath: true
|
||||||
|
nginx_default_hsts: 'max-age=63072000; includeSubDomains'
|
||||||
|
|
||||||
#
|
#
|
||||||
# Nginx directories
|
# Nginx directories
|
||||||
@@ -84,6 +85,18 @@ nginx_http_gzip_disable: '"msie6"'
|
|||||||
#
|
#
|
||||||
nginx_custom_http: []
|
nginx_custom_http: []
|
||||||
|
|
||||||
|
#
|
||||||
|
# Nginx default
|
||||||
|
#
|
||||||
|
nginx_default_listen:
|
||||||
|
- '80'
|
||||||
|
- '[::]:80'
|
||||||
|
nginx_default_listen_ssl:
|
||||||
|
- '443'
|
||||||
|
- '[::]:443'
|
||||||
|
nginx_default_listen_proxy_protocol: []
|
||||||
|
nginx_default_listen_proxy_protocol_ssl: []
|
||||||
|
|
||||||
#
|
#
|
||||||
# Sites
|
# Sites
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -1,11 +1,6 @@
|
|||||||
Auth Basic management
|
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
|
Description
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
|
|||||||
@@ -10,9 +10,3 @@ About modules
|
|||||||
-------------
|
-------------
|
||||||
|
|
||||||
Dynamic modules must be set with full path (see `nginx_load_modules` path).
|
Dynamic modules must be set with full path (see `nginx_load_modules` path).
|
||||||
|
|
||||||
Sites not tested
|
|
||||||
----------------
|
|
||||||
|
|
||||||
- BackupPC
|
|
||||||
- Nagios
|
|
||||||
|
|||||||
13
doc/php.md
13
doc/php.md
@@ -2,8 +2,7 @@ PHP
|
|||||||
===
|
===
|
||||||
|
|
||||||
`nginx_php`:
|
`nginx_php`:
|
||||||
- `version`: (M) PHP version
|
- `upstream_name` (M)
|
||||||
- `upstream_name` (O)
|
|
||||||
- `sockets`: (O) socket list
|
- `sockets`: (O) socket list
|
||||||
|
|
||||||
If `sockets` is not provided, if uses local unix socket (based on PHP version).
|
If `sockets` is not provided, if uses local unix socket (based on PHP version).
|
||||||
@@ -16,8 +15,8 @@ Each socket have:
|
|||||||
|
|
||||||
XOR
|
XOR
|
||||||
|
|
||||||
- `host`
|
- `host` (M)
|
||||||
- `port`
|
- `port` (M)
|
||||||
- `weight`
|
- `weight` (O)
|
||||||
- `max_fails`
|
- `max_fails` (O)
|
||||||
- `fail_timeout`
|
- `fail_timeout` (O)
|
||||||
|
|||||||
105
doc/site.md
105
doc/site.md
@@ -9,16 +9,34 @@ Common
|
|||||||
------
|
------
|
||||||
|
|
||||||
- `name`: (M) Domain or list of domain used.
|
- `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".
|
- `state`: (O) Site status. Can be "present" (default), "absent" and "disabled".
|
||||||
|
- `filename`: (O) Specify filename in `/etc/nginx/sites-*`. Do NOT specify default (reserved keyword). It will be used for log filenames and directories creation.
|
||||||
|
|
||||||
|
(O): Optional
|
||||||
|
(M): Mandatory
|
||||||
|
(D): Depends other keys...
|
||||||
|
|
||||||
|
You can use 2 config (at the same time time):
|
||||||
|
|
||||||
|
- pre-built: Some configuration are templated (Wordpress, Symfony...), auto create root dir, perform an "A+" on ssllabs for https... etc
|
||||||
|
- custom: Push your own site config template. Usefull when you have a complex configuration.
|
||||||
|
|
||||||
|
|
||||||
|
Pre-built site config
|
||||||
|
---------------------
|
||||||
|
|
||||||
|
# Keys
|
||||||
|
|
||||||
|
- `template`: (M) template used to create site. Optional if you set `state`=`absent` or using `redirect_to`.
|
||||||
- `redirect_from`: (O) Domain list to redirect to the first `name`. You can use this key to redirect non-www to www
|
- `redirect_from`: (O) Domain list to redirect to the first `name`. You can use this key to redirect non-www to www
|
||||||
- `redirect_to`: (O) Redirect all requests to this domain. Please set scheme (http:// or https:// or $sheme).
|
- `redirect_to`: (O) Redirect all requests to this domain. Please set scheme (http:// or https:// or $sheme).
|
||||||
- `headers`: (O) Set additionals header as key/value list. You can append "always" to the value. Show [nginx doc](http://nginx.org/en/docs/http/ngx_http_headers_module.html).
|
- `headers`: (O) Set additionals header as key/value list. You can append "always" to the value. Show [nginx doc](http://nginx.org/en/docs/http/ngx_http_headers_module.html).
|
||||||
- `redirect_to_code`: Redirect code (default: 302)
|
- `redirect_to_code`: Redirect code (default: 302)
|
||||||
- `redirect_https`: (O) Boolean. Redirect HTTP to HTTPS. If "true", you _MUST_ set `proto` to ```['https']```.
|
- `redirect_https`: (O) Boolean. Redirect HTTP to HTTPS. If "true", you _MUST_ set `proto` to `['https']`.
|
||||||
- `location`: (O) Add new custom locations (it does not overwrite!)
|
- `location`: (O) Add new custom locations (it does not overwrite!)
|
||||||
- `location_order`: (O) Due to non preditive `location` order, you can provide the good order (see test-location.local in [tests/test.yml](../tests/test.yml)).
|
- `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)).
|
||||||
|
- `location_before`: (O) Add new custom locations before generated location by template
|
||||||
|
- `location_order_before`: (O) Manages location order for `location_before`
|
||||||
- `more`: (O) Add more custom infos.
|
- `more`: (O) Add more custom infos.
|
||||||
- `upstream_params`: (O) Add upstream params (useful when you want to pass variables to PHP)
|
- `upstream_params`: (O) Add upstream params (useful when you want to pass variables to PHP)
|
||||||
- `override_try_files`: (O) overrides default try\_files defined in template
|
- `override_try_files`: (O) overrides default try\_files defined in template
|
||||||
@@ -27,22 +45,15 @@ Common
|
|||||||
- `proto`: (O) list of protocol used. Default is a list with "http". If you need http and https, you must set a list with "http" and "https". You can only set "https" without http support.
|
- `proto`: (O) list of protocol used. Default is a list with "http". If you need http and https, you must set a list with "http" and "https". You can only set "https" without http support.
|
||||||
- `ssl_name`: (D) name of the key used when using TLS/SSL. Optional when `proto` contains "https". If you don't set this value, it will search by `name`.
|
- `ssl_name`: (D) name of the key used when using TLS/SSL. Optional when `proto` contains "https". If you don't set this value, it will search by `name`.
|
||||||
- `ssl_template` (O) "strong" (default) or "legacy". You can disable SSL helpers and add your own directives by setting "false".
|
- `ssl_template` (O) "strong" (default) or "legacy". You can disable SSL helpers and add your own directives by setting "false".
|
||||||
- `php_version` (O) Sepecify PHP version (5 or 7)
|
- `listen_proxy_protocol` (O) Enable proxy protocol on http port.
|
||||||
- `http_proxy_protocol_port` (O) Enable proxy protocol on http port.
|
- `listen_proxy_protocol_ssl` (O) Enable proxy protocol on https port.
|
||||||
- `https_proxy_protocol_port` (O) Enable proxy protocol on https port.
|
- `hsts` (O) overwrite default header for hsts
|
||||||
|
|
||||||
(O): Optional
|
### Templates
|
||||||
(M): Mandatory
|
|
||||||
(D): Depends other keys...
|
|
||||||
|
|
||||||
Templates
|
|
||||||
---------
|
|
||||||
|
|
||||||
- `_base`: static template
|
- `_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`
|
- `_dokuwiki`
|
||||||
- `_redirect`: should not be called explicitly
|
- `_redirect`: should not be called explicitly
|
||||||
- `_nagios3`: access to Nagios3 (be careful: you need to install [fcgiwrap](https://packages.debian.org/jessie/fcgiwrap))
|
|
||||||
- `_phalcon`: Phalcon PHP Framework
|
- `_phalcon`: Phalcon PHP Framework
|
||||||
- `_php`: PHP base template. Can work with many frameworks/tools
|
- `_php`: PHP base template. Can work with many frameworks/tools
|
||||||
- `_php_index`: Same as above. But you can only run index.php
|
- `_php_index`: Same as above. But you can only run index.php
|
||||||
@@ -51,8 +62,7 @@ Templates
|
|||||||
|
|
||||||
Templates works as parent-child.
|
Templates works as parent-child.
|
||||||
|
|
||||||
About proxy template
|
### About proxy template
|
||||||
--------------------
|
|
||||||
|
|
||||||
Proxy template allow you to use Nginx as reverse proxy. Usefull when you have an application service such as Redmine, Jenkins...
|
Proxy template allow you to use Nginx as reverse proxy. Usefull when you have an application service such as Redmine, Jenkins...
|
||||||
|
|
||||||
@@ -63,10 +73,69 @@ You have many key added to site key:
|
|||||||
|
|
||||||
(O) : Optional
|
(O) : Optional
|
||||||
|
|
||||||
Default sites
|
### Default sites
|
||||||
--------------
|
|
||||||
|
|
||||||
You can manage default site by setting domain name to these variables.
|
You can manage default site by setting domain name to these variables.
|
||||||
|
|
||||||
- `nginx_default_site`
|
- `nginx_default_site`
|
||||||
- `nginx_default_site_ssl`
|
- `nginx_default_site_ssl`
|
||||||
|
|
||||||
|
*IT WORKS ONLY WITH PRE-BUIT SITES*
|
||||||
|
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- nginx_sites:
|
||||||
|
- name: 'mywebsite.com'
|
||||||
|
template: '_wordpress'
|
||||||
|
headers:
|
||||||
|
x-ansibled: '1'
|
||||||
|
manage_local_content: false
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
Custom site config
|
||||||
|
------------------
|
||||||
|
|
||||||
|
### Keys
|
||||||
|
|
||||||
|
- `custom_template`: (M) template path used
|
||||||
|
|
||||||
|
You can add some extra infos if needed.
|
||||||
|
|
||||||
|
### Example:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- nginx_sites:
|
||||||
|
- name: 'mycustom-website.com'
|
||||||
|
custom_template: 'my/template_dir/the-template.conf.j2'
|
||||||
|
allow_admin: '192.168.0.0/24'
|
||||||
|
```
|
||||||
|
|
||||||
|
In `my/template_dir/the-template.conf.j2`:
|
||||||
|
|
||||||
|
```
|
||||||
|
#
|
||||||
|
# {{ ansible_managed }} - {{ item.name }}
|
||||||
|
#
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 8080 http2 proxy_protocol;
|
||||||
|
server_name {{ item.name }};
|
||||||
|
index index.html;
|
||||||
|
root /var/www/{{ item.name }};
|
||||||
|
|
||||||
|
location / {
|
||||||
|
try_files $uri $uri/ =404;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /admin {
|
||||||
|
allow {{ item.allow_admin }};
|
||||||
|
deny all;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
34
doc/ssl.md
34
doc/ssl.md
@@ -15,24 +15,41 @@ Variables
|
|||||||
Cert/Key pairs
|
Cert/Key pairs
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
This list have 3 mandatory keys:
|
Each pair must have a `name`.
|
||||||
|
Note: `name` is used to deploy key/cert. With defaults values dans `name` = "foo", key is -> /etc/nginx/ssl/foo/foo.key
|
||||||
|
|
||||||
- `name`: MUST be unique
|
### Content mode
|
||||||
|
|
||||||
|
Key/Cert content is stored in variable. Usefull with vault.
|
||||||
|
|
||||||
- `key`: content of the private key
|
- `key`: content of the private key
|
||||||
- `cert`: content of the public key
|
- `cert`: content of the public key
|
||||||
|
|
||||||
OR
|
### Remote file
|
||||||
|
|
||||||
|
You can use these variables if you use another task/role to manages your certificates.
|
||||||
|
|
||||||
- `dest_cert`: remote path where certificate is located
|
- `dest_cert`: remote path where certificate is located
|
||||||
- `dest_key`: remote path where key is located
|
- `dest_key`: remote path where key is located
|
||||||
|
|
||||||
Note: `name` is used to deploy key/cert. With defaults values dans `name` = "foo", key is -> /etc/nginx/ssl/foo/foo.key
|
### Self signed
|
||||||
|
|
||||||
|
Create a self-signed pair and deploy it. Do not use this feature in production.
|
||||||
|
|
||||||
|
- `self_signed`: set true to use this featrure
|
||||||
|
- `force`: optional feature (default: false), force regen pair (not idempotent)
|
||||||
|
|
||||||
|
### Acme
|
||||||
|
|
||||||
|
Uses acme.sh to create free certificates. It uses HTTP-01 challenge. Use this feature for standalone servers.
|
||||||
|
|
||||||
|
- `acme`: set true to use this feature. It uses `name` (can be a string or string list).
|
||||||
|
|
||||||
|
Have a look to [acme configuratuion](acme.md configuration).
|
||||||
|
|
||||||
Tips
|
Tips
|
||||||
----
|
----
|
||||||
|
|
||||||
- Deploying key/cert is not mandatory with this role. You can manage it in other place ([letsencrypt](https://letsencrypt.org/)? :)). You just need to set `dest_cert` and `dest_key`!
|
|
||||||
- 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).
|
- 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
|
Diffie-Hellman
|
||||||
@@ -55,6 +72,10 @@ nginx_sites;
|
|||||||
- name: 'test-ssl3.local'
|
- name: 'test-ssl3.local'
|
||||||
proto: ['http', 'https']
|
proto: ['http', 'https']
|
||||||
template: '_base'
|
template: '_base'
|
||||||
|
- name: 'test-self-signed.local'
|
||||||
|
proto: ['http', 'https']
|
||||||
|
template: '_base'
|
||||||
|
ssl_name: 'this.is.self.signed'
|
||||||
|
|
||||||
nginx_ssl_pairs:
|
nginx_ssl_pairs:
|
||||||
- name: mysuperkey
|
- name: mysuperkey
|
||||||
@@ -68,5 +89,8 @@ nginx_ssl_pairs:
|
|||||||
-----END CERTIFICATE-----
|
-----END CERTIFICATE-----
|
||||||
- name: test-ssl2.local
|
- name: test-ssl2.local
|
||||||
acme: true
|
acme: true
|
||||||
|
- name: this.is.self.signed
|
||||||
|
self_signed: true
|
||||||
|
force: false
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,6 @@ Upstream management
|
|||||||
|
|
||||||
`nginx_upstreams`: List of dict. An upstream has few keys. See bellow.
|
`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
|
Upstream params
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
def nginx_site_filename(site):
|
def nginx_site_filename(site):
|
||||||
if site.has_key('filename'):
|
if 'filename' in site:
|
||||||
return site['filename']
|
return site['filename']
|
||||||
else:
|
else:
|
||||||
return nginx_site_name(site)
|
return nginx_site_name(site)
|
||||||
@@ -10,11 +10,59 @@ def nginx_site_name(site):
|
|||||||
else:
|
else:
|
||||||
return site['name']
|
return site['name']
|
||||||
|
|
||||||
|
def nginx_ssl_dir(pair, ssl_dir):
|
||||||
|
return ssl_dir + '/' + nginx_site_filename(pair)
|
||||||
|
|
||||||
|
def nginx_key_path(pair, ssl_dir):
|
||||||
|
if 'dest_key' in pair:
|
||||||
|
return pair['dest_key']
|
||||||
|
else:
|
||||||
|
return nginx_ssl_dir(pair, ssl_dir) + '/' + nginx_site_filename(pair) + '.key'
|
||||||
|
|
||||||
|
def nginx_cert_path(pair, ssl_dir):
|
||||||
|
if 'dest_cert' in pair:
|
||||||
|
return pair['dest_cert']
|
||||||
|
else:
|
||||||
|
return nginx_ssl_dir(pair, ssl_dir) + '/' + nginx_site_filename(pair) + '.crt'
|
||||||
|
|
||||||
|
def nginx_all_site_names(site):
|
||||||
|
all_sites = []
|
||||||
|
if isinstance(site['name'], list):
|
||||||
|
all_sites = all_sites + site['name']
|
||||||
|
else:
|
||||||
|
all_sites.append(site['name'])
|
||||||
|
|
||||||
|
if 'redirect_from' in site:
|
||||||
|
if isinstance(site['redirect_from'], list):
|
||||||
|
all_sites = all_sites + site['redirect_from']
|
||||||
|
else:
|
||||||
|
all_sites.append(site['redirect_from'])
|
||||||
|
|
||||||
|
return all_sites
|
||||||
|
|
||||||
|
def nginx_search_by_ssl_name(sites, ssl_name):
|
||||||
|
if isinstance(ssl_name, list):
|
||||||
|
comp_ssl_name = ssl_name[0]
|
||||||
|
else:
|
||||||
|
comp_ssl_name = ssl_name
|
||||||
|
|
||||||
|
res = None
|
||||||
|
for site in sites:
|
||||||
|
if 'ssl_name' in site and site['ssl_name'] == comp_ssl_name:
|
||||||
|
res = site
|
||||||
|
break
|
||||||
|
return res
|
||||||
|
|
||||||
class FilterModule(object):
|
class FilterModule(object):
|
||||||
''' Nginx module '''
|
''' Nginx module '''
|
||||||
|
|
||||||
def filters(self):
|
def filters(self):
|
||||||
return {
|
return {
|
||||||
'nginx_site_filename': nginx_site_filename,
|
'nginx_site_filename': nginx_site_filename,
|
||||||
'nginx_site_name': nginx_site_name
|
'nginx_site_name': nginx_site_name,
|
||||||
|
'nginx_ssl_dir': nginx_ssl_dir,
|
||||||
|
'nginx_key_path': nginx_key_path,
|
||||||
|
'nginx_cert_path': nginx_cert_path,
|
||||||
|
'nginx_all_site_names': nginx_all_site_names,
|
||||||
|
'nginx_search_by_ssl_name': nginx_search_by_ssl_name
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,10 @@
|
|||||||
def php_default_upstream_socket(php_version):
|
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
|
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):
|
class FilterModule(object):
|
||||||
''' PHP module '''
|
''' PHP module '''
|
||||||
|
|
||||||
def filters(self):
|
def filters(self):
|
||||||
return {
|
return {
|
||||||
'php_default_upstream_socket': php_default_upstream_socket,
|
'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,42 +1,46 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
- name: reload nginx
|
- name: reload nginx
|
||||||
command: nginx -t
|
ansible.builtin.command: nginx -t
|
||||||
notify:
|
notify:
|
||||||
- real-reload nginx
|
- real-reload nginx
|
||||||
- docker reload nginx
|
- docker reload nginx
|
||||||
|
|
||||||
- name: restart nginx
|
- name: restart nginx
|
||||||
command: nginx -t
|
ansible.builtin.command: nginx -t
|
||||||
notify:
|
notify:
|
||||||
- real-restart nginx
|
- real-restart nginx
|
||||||
- docker restart nginx
|
- docker restart nginx
|
||||||
|
|
||||||
- name: real-reload nginx
|
- name: real-reload nginx
|
||||||
service:
|
ansible.builtin.service:
|
||||||
name: nginx
|
name: nginx
|
||||||
state: reloaded
|
state: reloaded
|
||||||
when: ansible_virtualization_type != 'docker'
|
when: ansible_virtualization_type != 'docker'
|
||||||
|
|
||||||
- name: real-restart nginx
|
- name: real-restart nginx
|
||||||
service:
|
ansible.builtin.service:
|
||||||
name: nginx
|
name: nginx
|
||||||
state: restarted
|
state: restarted
|
||||||
when: ansible_virtualization_type != 'docker'
|
when: ansible_virtualization_type != 'docker'
|
||||||
|
|
||||||
- name: docker reload nginx
|
- name: docker reload nginx
|
||||||
command: service nginx reload
|
ansible.builtin.command: service nginx reload
|
||||||
|
args:
|
||||||
|
warn: false
|
||||||
when: ansible_virtualization_type == 'docker'
|
when: ansible_virtualization_type == 'docker'
|
||||||
|
|
||||||
- name: docker restart nginx
|
- name: docker restart nginx
|
||||||
command: service nginx restart
|
ansible.builtin.command: service nginx restart
|
||||||
|
args:
|
||||||
|
warn: false
|
||||||
when: ansible_virtualization_type == 'docker'
|
when: ansible_virtualization_type == 'docker'
|
||||||
|
|
||||||
- name: restart nginx freebsd
|
- name: restart nginx freebsd
|
||||||
service:
|
ansible.builtin.service:
|
||||||
name: nginx
|
name: nginx
|
||||||
state: restarted
|
state: restarted
|
||||||
when: ansible_distribution == "FreeBSD"
|
when: ansible_distribution == "FreeBSD"
|
||||||
|
|
||||||
- name: setup
|
- name: setup
|
||||||
action: setup
|
ansible.builtin.setup:
|
||||||
|
|||||||
@@ -1,19 +1,27 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
galaxy_info:
|
galaxy_info:
|
||||||
author: Emilien Mantel
|
author: Emilien Mantel
|
||||||
description: Nginx for Debian
|
namespace: hanxhx
|
||||||
|
role_name: nginx
|
||||||
|
description: Nginx for Debian / FreeBSD
|
||||||
company:
|
company:
|
||||||
license: GPLv2
|
license: GPLv2
|
||||||
min_ansible_version: 2.2
|
min_ansible_version: 2.11
|
||||||
platforms:
|
platforms:
|
||||||
- name: Debian
|
- name: Debian
|
||||||
versions:
|
versions:
|
||||||
- jessie
|
- stretch
|
||||||
|
- buster
|
||||||
|
- bullseye
|
||||||
- name: FreeBSD
|
- name: FreeBSD
|
||||||
versions:
|
versions:
|
||||||
- 10.2
|
- 11.0
|
||||||
|
- 11.1
|
||||||
|
- 12.0
|
||||||
galaxy_tags:
|
galaxy_tags:
|
||||||
- web
|
- web
|
||||||
|
- debian
|
||||||
- proxy
|
- proxy
|
||||||
- http
|
- http
|
||||||
- http2
|
- http2
|
||||||
@@ -23,4 +31,3 @@ galaxy_info:
|
|||||||
- nginx
|
- nginx
|
||||||
- cdn
|
- cdn
|
||||||
dependencies: []
|
dependencies: []
|
||||||
|
|
||||||
|
|||||||
@@ -1,44 +1,57 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
- name: TEMPLATE | Deploy nginx.conf
|
- name: TEMPLATE | Deploy nginx.conf
|
||||||
template:
|
ansible.builtin.template:
|
||||||
src: "etc/nginx/nginx.conf.j2"
|
src: "etc/nginx/nginx.conf.j2"
|
||||||
dest: "{{ nginx_etc_dir }}/nginx.conf"
|
dest: "{{ nginx_etc_dir }}/nginx.conf"
|
||||||
|
mode: 0644
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
notify: reload nginx
|
notify: reload nginx
|
||||||
|
|
||||||
- name: TEMPLATE | Deploy all helpers
|
- name: TEMPLATE | Deploy all helpers
|
||||||
template:
|
ansible.builtin.template:
|
||||||
src: "{{ item }}"
|
src: "{{ item }}"
|
||||||
dest: "{{ nginx_helper_dir }}/{{ item | basename | regex_replace('.j2$','') }}"
|
dest: "{{ nginx_helper_dir }}/{{ item | basename | regex_replace('.j2$','') }}"
|
||||||
|
mode: 0644
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
with_fileglob: '../templates/etc/nginx/helper/*.j2'
|
with_fileglob: '../templates/etc/nginx/helper/*.j2'
|
||||||
notify: reload nginx
|
notify: reload nginx
|
||||||
|
|
||||||
- name: TEMPLATE | Deploy custom http configuration
|
- name: TEMPLATE | Deploy custom http configuration
|
||||||
template:
|
ansible.builtin.template:
|
||||||
src: "etc/nginx/conf.d/custom.conf.j2"
|
src: "etc/nginx/conf.d/custom.conf.j2"
|
||||||
dest: "{{ nginx_etc_dir }}/conf.d/custom.conf"
|
dest: "{{ nginx_etc_dir }}/conf.d/custom.conf"
|
||||||
|
mode: 0644
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
notify: reload nginx
|
notify: reload nginx
|
||||||
|
|
||||||
- name: LINEINFILE | Fix path
|
- name: LINEINFILE | Fix path
|
||||||
lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
regexp: '{{ item.0.regexp }}'
|
regexp: '{{ item.0.regexp }}'
|
||||||
line: '{{ item.0.line }}'
|
line: '{{ item.0.line }}'
|
||||||
dest: '{{ item.1 }}'
|
dest: '{{ item.1 }}'
|
||||||
with_nested:
|
loop: "{{ list_one | product(list_two) | list }}"
|
||||||
-
|
vars:
|
||||||
|
list_one:
|
||||||
- regexp: '^fastcgi_param SCRIPT_FILENAME'
|
- regexp: '^fastcgi_param SCRIPT_FILENAME'
|
||||||
line: 'fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;'
|
line: 'fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;'
|
||||||
- regexp: '^fastcgi_param DOCUMENT_ROOT'
|
- regexp: '^fastcgi_param DOCUMENT_ROOT'
|
||||||
line: 'fastcgi_param DOCUMENT_ROOT $realpath_root;'
|
line: 'fastcgi_param DOCUMENT_ROOT $realpath_root;'
|
||||||
-
|
list_two:
|
||||||
- '{{ nginx_etc_dir }}/fastcgi.conf'
|
- '{{ nginx_etc_dir }}/fastcgi.conf'
|
||||||
when: nginx_fastcgi_fix_realpath
|
when: nginx_fastcgi_fix_realpath
|
||||||
|
|
||||||
- name: COPY | Add modules manually
|
- name: COPY | Add modules manually
|
||||||
copy:
|
ansible.builtin.copy:
|
||||||
content: |
|
content: |
|
||||||
{% for m in nginx_load_modules %}
|
{% for m in nginx_load_modules %}
|
||||||
load_module {{ m }};
|
load_module {{ m }};
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
dest: "{{ nginx_etc_dir }}/modules-enabled/000-modules.conf"
|
dest: "{{ nginx_etc_dir }}/modules-enabled/000-modules.conf"
|
||||||
|
mode: 0644
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
notify: reload nginx
|
notify: reload nginx
|
||||||
|
|||||||
@@ -1,21 +1,21 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
- name: FILE | Delete htpasswd file
|
- name: FILE | Delete htpasswd file
|
||||||
file:
|
ansible.builtin.file:
|
||||||
path: "{{ nginx_htpasswd_dir }}/{{ item.name }}"
|
path: "{{ nginx_htpasswd_dir }}/{{ item.name }}"
|
||||||
state: absent
|
state: absent
|
||||||
with_items: "{{ nginx_htpasswd }}"
|
loop: "{{ nginx_htpasswd }}"
|
||||||
when: item.state is defined and item.state == 'absent'
|
when: item.state is defined and item.state == 'absent'
|
||||||
no_log: not nginx_debug_role
|
no_log: "{{ not nginx_debug_role }}"
|
||||||
|
|
||||||
- name: HTPASSWD | Manage files
|
- name: HTPASSWD | Manage files
|
||||||
htpasswd:
|
ansible.builtin.htpasswd:
|
||||||
name: "{{ item.1.name }}"
|
name: "{{ item.1.name }}"
|
||||||
password: "{{ item.1.password }}"
|
password: "{{ item.1.password }}"
|
||||||
state: "{{ item.1.state | default('present') }}"
|
|
||||||
path: "{{ nginx_htpasswd_dir }}/{{ item.0.name }}"
|
path: "{{ nginx_htpasswd_dir }}/{{ item.0.name }}"
|
||||||
with_subelements:
|
mode: 0644
|
||||||
- "{{ nginx_htpasswd }}"
|
owner: root
|
||||||
- users
|
group: root
|
||||||
|
loop: "{{ nginx_htpasswd | subelements('users') }}"
|
||||||
when: item.0.state is not defined or item.0.state == 'present'
|
when: item.0.state is not defined or item.0.state == 'present'
|
||||||
no_log: not nginx_debug_role
|
no_log: "{{ not nginx_debug_role }}"
|
||||||
|
|||||||
@@ -1,65 +1,51 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
- name: FAIL | Check possible issues
|
- name: SET_FACT | Bypass https://github.com/ansible/ansible/issues/19874
|
||||||
fail:
|
ansible.builtin.set_fact:
|
||||||
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"
|
ansible_distribution_release: 'buster'
|
||||||
when:
|
when: ansible_facts.distribution_major_version == "buster/sid"
|
||||||
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
|
- name: APT | Update cache
|
||||||
apt:
|
ansible.builtin.apt:
|
||||||
update_cache: yes
|
update_cache: true
|
||||||
cache_valid_time: 3600
|
cache_valid_time: 3600
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
|
||||||
- name: APT | Force OpenSSL from backports (fix dependency break)
|
|
||||||
apt:
|
|
||||||
pkg: openssl
|
|
||||||
state: latest
|
|
||||||
default_release: "{{ ansible_distribution_release + '-backports' }}"
|
|
||||||
when: nginx_backports
|
|
||||||
|
|
||||||
- name: APT | Install nginx and dependencies
|
- name: APT | Install nginx and dependencies
|
||||||
apt:
|
ansible.builtin.apt:
|
||||||
pkg: "{{ nginx_apt_package }}"
|
pkg: "{{ nginx_apt_package }}"
|
||||||
state: present
|
|
||||||
default_release: "{{ ansible_distribution_release + '-backports' if nginx_backports else ansible_distribution_release }}"
|
default_release: "{{ ansible_distribution_release + '-backports' if nginx_backports else ansible_distribution_release }}"
|
||||||
|
|
||||||
- name: APT | Install nginx modules
|
- name: APT | Install nginx modules
|
||||||
apt:
|
ansible.builtin.apt:
|
||||||
pkg: "{{ item }}"
|
pkg: "{{ nginx_module_packages }}"
|
||||||
state: present
|
state: present
|
||||||
with_items: "{{ nginx_module_packages }}"
|
|
||||||
when:
|
|
||||||
ansible_distribution_major_version | version_compare('9', 'ge') or
|
|
||||||
nginx_backports
|
|
||||||
|
|
||||||
- name: APT | Install python-passlib
|
- name: APT | Install python-passlib
|
||||||
apt:
|
ansible.builtin.apt:
|
||||||
pkg: python-passlib
|
pkg: "python{% if ansible_python_version is version('3', '>=') %}3{% endif %}-passlib"
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
- name: STAT | Check acme.sh is installed
|
- name: STAT | Check acme.sh is installed
|
||||||
stat:
|
ansible.builtin.stat:
|
||||||
path: "{{ nginx_acmesh_dir }}"
|
path: "{{ nginx_acmesh_dir }}"
|
||||||
register: acme
|
register: acme
|
||||||
|
|
||||||
- block:
|
- block:
|
||||||
|
|
||||||
- name: APT | Install git
|
- name: APT | Install git
|
||||||
apt:
|
ansible.builtin.apt:
|
||||||
pkg: git
|
pkg: git
|
||||||
|
|
||||||
- name: GIT | Get acme.sh
|
- name: GIT | Get acme.sh
|
||||||
git:
|
ansible.builtin.git:
|
||||||
repo: 'https://github.com/Neilpang/acme.sh.git'
|
repo: 'https://github.com/Neilpang/acme.sh.git'
|
||||||
dest: '{{ nginx_acmesh_git_dir }}'
|
dest: '{{ nginx_acmesh_git_dir }}'
|
||||||
update: no
|
update: false
|
||||||
|
version: master
|
||||||
|
|
||||||
- name: SHELL | Install acme.sh
|
- name: COMMAND | Install acme.sh
|
||||||
shell: ./acme.sh --install --home {{ nginx_acmesh_dir }} --cert-home {{ nginx_acmesh_dir }}
|
ansible.builtin.command: ./acme.sh --install --home "{{ nginx_acmesh_dir }}"
|
||||||
args:
|
args:
|
||||||
chdir: "{{ nginx_acmesh_git_dir }}"
|
chdir: "{{ nginx_acmesh_git_dir }}"
|
||||||
creates: "{{ nginx_acmesh_dir }}"
|
creates: "{{ nginx_acmesh_dir }}"
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
pkgng:
|
pkgng:
|
||||||
name: "{{ item }}"
|
name: "{{ item }}"
|
||||||
state: present
|
state: present
|
||||||
with_items:
|
loop:
|
||||||
- acme.sh
|
- acme.sh
|
||||||
- "{{ nginx_pkgng_package }}"
|
- "{{ nginx_pkgng_package }}"
|
||||||
- py27-passlib
|
- py27-passlib
|
||||||
@@ -16,20 +16,20 @@
|
|||||||
- block:
|
- block:
|
||||||
|
|
||||||
- name: COMMAND | Create /usr/local/etc/fdfs/http.conf
|
- name: COMMAND | Create /usr/local/etc/fdfs/http.conf
|
||||||
command: touch /usr/local/etc/fdfs/http.conf
|
ansible.builtin.command: touch /usr/local/etc/fdfs/http.conf
|
||||||
args:
|
args:
|
||||||
creates: /usr/local/etc/fdfs/http.conf
|
creates: /usr/local/etc/fdfs/http.conf
|
||||||
register: fd1
|
register: fd1
|
||||||
|
|
||||||
- name: LINEINFILE | Tune fdfs
|
- name: LINEINFILE | Tune fdfs
|
||||||
lineinfile:
|
ansible.builtin.lineinansible.builtin.file:
|
||||||
regexp: ^load_fdfs_parameters_from_tracker
|
regexp: ^load_fdfs_parameters_from_tracker
|
||||||
line: load_fdfs_parameters_from_tracker=false
|
line: load_fdfs_parameters_from_tracker=false
|
||||||
path: /usr/local/etc/fdfs/mod_fastdfs.conf
|
path: /usr/local/etc/fdfs/mod_fastdfs.conf
|
||||||
register: fd2
|
register: fd2
|
||||||
|
|
||||||
- name: SERVICE | Restart nginx when fdfs is tuned
|
- name: SERVICE | Restart nginx when fdfs is tuned
|
||||||
service:
|
ansible.builtin.service:
|
||||||
name: nginx
|
name: nginx
|
||||||
state: restarted
|
state: restarted
|
||||||
when: fd1.changed or fd2.changed
|
when: fd1.changed or fd2.changed
|
||||||
@@ -37,16 +37,19 @@
|
|||||||
when: true
|
when: true
|
||||||
|
|
||||||
- name: FILE | Create configuration dir (like Debian)
|
- name: FILE | Create configuration dir (like Debian)
|
||||||
file:
|
ansible.builtin.file:
|
||||||
path: "{{ nginx_etc_dir }}/{{ item }}"
|
path: "{{ nginx_etc_dir }}/{{ item }}"
|
||||||
state: directory
|
state: directory
|
||||||
with_items:
|
mode: 0755
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
loop:
|
||||||
- conf.d
|
- conf.d
|
||||||
- sites-available
|
- sites-available
|
||||||
- sites-enabled
|
- sites-enabled
|
||||||
|
|
||||||
- name: FILE | Create log directory
|
- name: FILE | Create log directory
|
||||||
file:
|
ansible.builtin.file:
|
||||||
path: "{{ nginx_log_dir }}"
|
path: "{{ nginx_log_dir }}"
|
||||||
owner: "{{ nginx_user }}"
|
owner: "{{ nginx_user }}"
|
||||||
group: wheel
|
group: wheel
|
||||||
@@ -54,6 +57,6 @@
|
|||||||
state: directory
|
state: directory
|
||||||
|
|
||||||
- name: SERVICE | Enable nginx
|
- name: SERVICE | Enable nginx
|
||||||
service:
|
ansible.builtin.service:
|
||||||
name: nginx
|
name: nginx
|
||||||
enabled: yes
|
enabled: true
|
||||||
|
|||||||
@@ -1,30 +1,30 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
- name: INCLUDE_VARS | Related to OS
|
- name: INCLUDE_VARS | Related to OS
|
||||||
include_vars: "{{ ansible_distribution }}.yml"
|
ansible.builtin.include_vars: "{{ ansible_distribution }}.yml"
|
||||||
tags: ['nginx::site', 'nginx::ssl']
|
tags: ['nginx::site', 'nginx::ssl']
|
||||||
|
|
||||||
- name: INCLUDE | Install
|
- name: INCLUDE_TASKS | Install
|
||||||
include: "install_{{ ansible_distribution }}.yml"
|
ansible.builtin.include_tasks: "install_{{ ansible_distribution }}.yml"
|
||||||
tags: ['nginx::site', 'nginx::ssl']
|
tags: ['nginx::site', 'nginx::ssl']
|
||||||
|
|
||||||
- name: INCLUDE | Prepare
|
- name: IMPORT_TASKS| Prepare
|
||||||
include: prepare.yml
|
ansible.builtin.import_tasks: prepare.yml
|
||||||
tags: ['nginx::site', 'nginx::ssl']
|
tags: ['nginx::site', 'nginx::ssl']
|
||||||
|
|
||||||
- name: INCLUDE | Install
|
- name: IMPORT_TASKS| Install
|
||||||
include: config.yml
|
ansible.builtin.import_tasks: config.yml
|
||||||
|
|
||||||
- name: INCLUDE | Upstream configuration
|
- name: IMPORT_TASKS| Upstream configuration
|
||||||
include: upstream.yml
|
ansible.builtin.import_tasks: upstream.yml
|
||||||
|
|
||||||
- name: INCLUDE | htpasswd configuration
|
- name: IMPORT_TASKS| htpasswd configuration
|
||||||
include: htpasswd.yml
|
ansible.builtin.import_tasks: htpasswd.yml
|
||||||
|
|
||||||
- name: INCLUDE | SSL configuration
|
- name: IMPORT_TASKS| SSL configuration
|
||||||
include: ssl/main.yml
|
ansible.builtin.import_tasks: ssl/main.yml
|
||||||
tags: ['nginx::ssl']
|
tags: ['nginx::ssl']
|
||||||
|
|
||||||
- name: INCLUDE | Sites configuration
|
- name: IMPORT_TASKS| Sites configuration
|
||||||
include: site.yml
|
ansible.builtin.import_tasks: site.yml
|
||||||
tags: ['nginx::site']
|
tags: ['nginx::site']
|
||||||
|
|||||||
@@ -1,34 +1,47 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
- name: SHELL | Get Nginx version
|
- name: SHELL | Get Nginx version
|
||||||
shell: nginx -v 2>&1 | sed -r 's#.*/##;' | cut -d ' ' -f 1
|
ansible.builtin.shell: nginx -v 2>&1 | sed -r 's#.*/##;' | cut -d ' ' -f 1
|
||||||
args:
|
args:
|
||||||
executable: /bin/sh
|
executable: /bin/sh
|
||||||
register: nginx_version
|
register: nginx_version
|
||||||
changed_when: false
|
changed_when: false
|
||||||
check_mode: no
|
check_mode: false
|
||||||
|
tags:
|
||||||
|
- skip_ansible_lint
|
||||||
|
|
||||||
- name: SHELL | Get module list
|
- name: SHELL | Get module list
|
||||||
shell: nginx -V 2>&1 | tr -- - '\n' | grep -A 1 with | grep _module | sed -r 's/_module//g; s/\s+//g' | sort
|
ansible.builtin.shell: |
|
||||||
|
nginx -V 2>&1 |
|
||||||
|
tr -- - '\n' |
|
||||||
|
grep -A 1 with |
|
||||||
|
grep _module |
|
||||||
|
sed -r 's/_module//g; s/\s+//g' |
|
||||||
|
sort
|
||||||
args:
|
args:
|
||||||
executable: /bin/sh
|
executable: /bin/sh
|
||||||
register: shell_modules
|
register: shell_modules
|
||||||
changed_when: false
|
changed_when: false
|
||||||
check_mode: no
|
check_mode: false
|
||||||
|
tags:
|
||||||
|
- skip_ansible_lint
|
||||||
|
|
||||||
- name: SET_FACT | Save modules
|
- name: SET_FACT | Save modules
|
||||||
set_fact:
|
ansible.builtin.set_fact:
|
||||||
nginx_modules: "{{ shell_modules.stdout_lines }}"
|
nginx_modules: "{{ shell_modules.stdout_lines }}"
|
||||||
|
|
||||||
- name: FILE | Create folders
|
- name: FILE | Create folders
|
||||||
file:
|
ansible.builtin.file:
|
||||||
dest: "{{ item.dir }}"
|
dest: "{{ item.dir }}"
|
||||||
owner: "{{ item.owner }}"
|
owner: "{{ item.owner }}"
|
||||||
mode: "{{ item.mode }}"
|
mode: "{{ item.mode }}"
|
||||||
state: directory
|
state: directory
|
||||||
with_items: "{{ nginx_dirs }}"
|
loop: "{{ nginx_dirs }}"
|
||||||
|
|
||||||
- name: FILE | Create ansible facts dir
|
- name: FILE | Create ansible facts dir
|
||||||
file:
|
ansible.builtin.file:
|
||||||
path: /etc/ansible/facts.d
|
path: /etc/ansible/facts.d
|
||||||
state: directory
|
state: directory
|
||||||
|
mode: 0755
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
|||||||
@@ -1,36 +1,39 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
- name: FAIL | Check filenames
|
- name: FAIL | Check filenames
|
||||||
fail:
|
ansible.builtin.fail:
|
||||||
msg: "Forbidden keyword default on site {{ item | nginx_site_name }}"
|
msg: "Forbidden keyword default on site {{ item | nginx_site_name }}"
|
||||||
when: item.filename is defined and item.filename == 'default'
|
when: item.filename is defined and item.filename == 'default'
|
||||||
with_items: "{{ nginx_sites }}"
|
loop: "{{ nginx_sites }}"
|
||||||
loop_control:
|
loop_control:
|
||||||
label: "{{ item | nginx_site_name }}"
|
label: "{{ item | nginx_site_name }}"
|
||||||
|
|
||||||
- name: FAIL | Check HTTPS redir and proto
|
- name: FAIL | Check HTTPS redir and proto
|
||||||
fail:
|
ansible.builtin.fail:
|
||||||
msg: "You can't have HTTP proto and HTTPS redirection at the same time"
|
msg: "You can't have HTTP proto and HTTPS redirection at the same time"
|
||||||
when:
|
when:
|
||||||
((item.proto is defined and 'http' in item.proto) or (item.proto is not defined)) and
|
((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)
|
(item.redirect_http is defined and item.redirect_http)
|
||||||
with_items: "{{ nginx_sites }}"
|
loop: "{{ nginx_sites }}"
|
||||||
loop_control:
|
loop_control:
|
||||||
label: "{{ item | nginx_site_name }}"
|
label: "{{ item | nginx_site_name }}"
|
||||||
|
|
||||||
- name: FILE | Create root directory
|
- name: FILE | Create root directory
|
||||||
file:
|
ansible.builtin.file:
|
||||||
path: "{{ nginx_root }}"
|
path: "{{ nginx_root }}"
|
||||||
state: directory
|
state: directory
|
||||||
|
mode: 0755
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
|
||||||
- name: FILE | Create root public folders (foreach nginx_sites)
|
- name: FILE | Create root public folders (foreach nginx_sites)
|
||||||
file:
|
ansible.builtin.file:
|
||||||
path: "{{ nginx_root }}/{{ item | nginx_site_filename }}/public"
|
path: "{{ nginx_root }}/{{ item | nginx_site_filename }}/public"
|
||||||
state: directory
|
state: directory
|
||||||
owner: "{{ item.owner | default(nginx_user) }}"
|
owner: "{{ item.owner | default(nginx_user) }}"
|
||||||
group: "{{ item.group | default(nginx_user) }}"
|
group: "{{ item.group | default(nginx_user) }}"
|
||||||
mode: "{{ item.mode | default('0755') }}"
|
mode: "{{ item.mode | default('0755') }}"
|
||||||
with_items: "{{ nginx_sites }}"
|
loop: "{{ nginx_sites }}"
|
||||||
when: >
|
when: >
|
||||||
item.root is not defined and
|
item.root is not defined and
|
||||||
(item.template is defined and item.template not in nginx_templates_no_dir) and
|
(item.template is defined and item.template not in nginx_templates_no_dir) and
|
||||||
@@ -40,33 +43,46 @@
|
|||||||
label: "{{ item | nginx_site_name }}"
|
label: "{{ item | nginx_site_name }}"
|
||||||
|
|
||||||
- name: TEMPLATE | Create sites
|
- name: TEMPLATE | Create sites
|
||||||
template:
|
ansible.builtin.template:
|
||||||
src: "etc/nginx/sites-available/{{ item.template if item.redirect_to is not defined else '_redirect' }}.j2"
|
src: "etc/nginx/sites-available/{{ item.template if item.redirect_to is not defined else '_redirect' }}.j2"
|
||||||
dest: "{{ nginx_etc_dir }}/sites-available/{{ item | nginx_site_filename }}"
|
dest: "{{ nginx_etc_dir }}/sites-available/{{ item | nginx_site_filename }}"
|
||||||
with_items: "{{ nginx_sites }}"
|
mode: 0644
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
notify: ['reload nginx', 'restart nginx freebsd']
|
notify: ['reload nginx', 'restart nginx freebsd']
|
||||||
when: item.state is not defined or item.state != 'absent'
|
when: (item.state is not defined or item.state != 'absent') and item.custom_template is not defined
|
||||||
|
loop: "{{ nginx_sites }}"
|
||||||
|
loop_control:
|
||||||
|
label: "{{ item | nginx_site_name }}"
|
||||||
|
|
||||||
|
- name: TEMPLATE | Create sites with preconfigured template
|
||||||
|
template:
|
||||||
|
src: "{{ item.custom_template }}"
|
||||||
|
dest: "{{ nginx_etc_dir }}/sites-available/{{ item | nginx_site_filename }}"
|
||||||
|
notify: ['reload nginx', 'restart nginx freebsd']
|
||||||
|
when: (item.state is not defined or item.state != 'absent') and item.custom_template is defined
|
||||||
|
loop: "{{ nginx_sites }}"
|
||||||
loop_control:
|
loop_control:
|
||||||
label: "{{ item | nginx_site_name }}"
|
label: "{{ item | nginx_site_name }}"
|
||||||
|
|
||||||
- name: FILE | Delete sites
|
- name: FILE | Delete sites
|
||||||
file:
|
ansible.builtin.file:
|
||||||
path: "{{ nginx_etc_dir }}/{{ item.1 }}/{{ item.0 | nginx_site_filename }}"
|
path: "{{ nginx_etc_dir }}/{{ item.1 }}/{{ item.0 | nginx_site_filename }}"
|
||||||
state: absent
|
state: absent
|
||||||
with_nested:
|
loop: "{{ nginx_sites | product(dirs) | list }}"
|
||||||
- "{{ nginx_sites }}"
|
|
||||||
- ['sites-available', 'sites-enabled']
|
|
||||||
notify: ['reload nginx', 'restart nginx freebsd']
|
notify: ['reload nginx', 'restart nginx freebsd']
|
||||||
when: item.0.state is defined and item.0.state == 'absent'
|
when: item.0.state is defined and item.0.state == 'absent'
|
||||||
|
vars:
|
||||||
|
dirs: ['sites-available', 'sites-enabled']
|
||||||
loop_control:
|
loop_control:
|
||||||
label: "{{ nginx_etc_dir }}/{{ item.1 }}/{{ item.0 | nginx_site_filename }}"
|
label: "{{ nginx_etc_dir }}/{{ item.1 }}/{{ item.0 | nginx_site_filename }}"
|
||||||
|
|
||||||
- name: FILE | Enable sites
|
- name: FILE | Enable sites
|
||||||
file:
|
ansible.builtin.file:
|
||||||
src: "{{ nginx_etc_dir }}/sites-available/{{ item | nginx_site_filename }}"
|
src: "{{ nginx_etc_dir }}/sites-available/{{ item | nginx_site_filename }}"
|
||||||
dest: "{{ nginx_etc_dir }}/sites-enabled/{{ item | nginx_site_filename }}"
|
dest: "{{ nginx_etc_dir }}/sites-enabled/{{ item | nginx_site_filename }}"
|
||||||
state: link
|
state: link
|
||||||
with_items: "{{ nginx_sites }}"
|
loop: "{{ nginx_sites }}"
|
||||||
notify: ['reload nginx', 'restart nginx freebsd']
|
notify: ['reload nginx', 'restart nginx freebsd']
|
||||||
when: >
|
when: >
|
||||||
item.state is not defined or item.state == 'present'
|
item.state is not defined or item.state == 'present'
|
||||||
@@ -74,24 +90,24 @@
|
|||||||
label: "{{ item | nginx_site_name }}"
|
label: "{{ item | nginx_site_name }}"
|
||||||
|
|
||||||
- name: FILE | Disable sites
|
- name: FILE | Disable sites
|
||||||
file:
|
ansible.builtin.file:
|
||||||
path: "{{ nginx_etc_dir}}/sites-enabled/{{ item | nginx_site_filename }}"
|
path: "{{ nginx_etc_dir }}/sites-enabled/{{ item | nginx_site_filename }}"
|
||||||
state: absent
|
state: absent
|
||||||
with_items: "{{ nginx_sites }}"
|
loop: "{{ nginx_sites }}"
|
||||||
notify: ['reload nginx', 'restart nginx freebsd']
|
notify: ['reload nginx', 'restart nginx freebsd']
|
||||||
when: item.state is defined and item.state == 'disabled'
|
when: item.state is defined and item.state == 'disabled'
|
||||||
loop_control:
|
loop_control:
|
||||||
label: "{{ item | nginx_site_name }}"
|
label: "{{ item | nginx_site_name }}"
|
||||||
|
|
||||||
- name: FILE | Delete default site when explicitely defined
|
- name: FILE | Delete default site when explicitely defined
|
||||||
file:
|
ansible.builtin.file:
|
||||||
path: "{{ nginx_etc_dir }}/sites-enabled/default"
|
path: "{{ nginx_etc_dir }}/sites-enabled/default"
|
||||||
state: absent
|
state: absent
|
||||||
notify: ['reload nginx', 'restart nginx freebsd']
|
notify: ['reload nginx', 'restart nginx freebsd']
|
||||||
when: nginx_default_site is not none
|
when: nginx_default_site is not none
|
||||||
|
|
||||||
- name: FILE | Auto set default site
|
- name: FILE | Auto set default site
|
||||||
file:
|
ansible.builtin.file:
|
||||||
src: "{{ nginx_etc_dir }}/sites-available/default"
|
src: "{{ nginx_etc_dir }}/sites-available/default"
|
||||||
dest: "{{ nginx_etc_dir }}/sites-enabled/default"
|
dest: "{{ nginx_etc_dir }}/sites-enabled/default"
|
||||||
state: link
|
state: link
|
||||||
@@ -99,7 +115,7 @@
|
|||||||
when: nginx_default_site is none
|
when: nginx_default_site is none
|
||||||
|
|
||||||
- name: TEMPLATE | Deploy facts
|
- name: TEMPLATE | Deploy facts
|
||||||
template:
|
ansible.builtin.template:
|
||||||
src: etc/ansible/facts.d/nginx.fact.j2
|
src: etc/ansible/facts.d/nginx.fact.j2
|
||||||
dest: /etc/ansible/facts.d/nginx.fact
|
dest: /etc/ansible/facts.d/nginx.fact
|
||||||
mode: 0644
|
mode: 0644
|
||||||
|
|||||||
@@ -1,63 +1,101 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
- name: SET_FACT | Assign default..
|
- name: SET_FACT | Assign default...
|
||||||
set_fact:
|
ansible.builtin.set_fact:
|
||||||
acme_create: []
|
acme_create: []
|
||||||
|
|
||||||
- name: STAT | Check if certificates are already installed
|
- name: STAT | Check if certificates are already installed
|
||||||
stat:
|
ansible.builtin.stat:
|
||||||
path: "{{ nginx_ssl_dir }}/{{ item | nginx_site_name }}/{{ item | nginx_site_name }}.crt"
|
path: "{{ item | nginx_cert_path(nginx_ssl_dir) }}"
|
||||||
with_items: "{{ nginx_ssl_pairs }}"
|
loop: "{{ nginx_ssl_pairs }}"
|
||||||
when: item.acme is defined and item.acme
|
when: item.acme is defined and item.acme
|
||||||
register: acme_installed_certs
|
register: acme_installed_certs
|
||||||
|
|
||||||
- name: SET_FACT | Assign var with certificates to create
|
- name: SET_FACT | Assign var with certificates to create
|
||||||
set_fact:
|
ansible.builtin.set_fact:
|
||||||
acme_create: "{{ acme_create | default([]) + [ (item.item | combine({'listen': ([item.item.acme_port|default(80)]) }) ) ] }}"
|
acme_create: "{{ acme_create | default([]) + [ (item.item) ] }}"
|
||||||
with_items: "{{ acme_installed_certs.results }}"
|
loop: "{{ acme_installed_certs.results }}"
|
||||||
when: item.skipped is not defined and not item.stat.exists
|
when: item.skipped is not defined and (not item.stat.exists or item.stat.size == 0)
|
||||||
|
|
||||||
- name: TEMPLATE | Create fake site
|
- name: BLOCK | Start acme
|
||||||
template:
|
block:
|
||||||
src: "etc/nginx/sites-available/_base.j2"
|
|
||||||
|
- name: TEMPLATE | Create fake site
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: "etc/nginx/conf.d/FAKESITE.conf.j2"
|
||||||
dest: "{{ nginx_etc_dir }}/conf.d/FAKESITE_{{ item | nginx_site_name }}.conf"
|
dest: "{{ nginx_etc_dir }}/conf.d/FAKESITE_{{ item | nginx_site_name }}.conf"
|
||||||
with_items: "{{ acme_create }}"
|
mode: 0644
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
loop: "{{ acme_create }}"
|
||||||
register: fake_site
|
register: fake_site
|
||||||
|
|
||||||
- name: SERVICE | Restart nginx
|
- name: FILE | Delete current site if needed
|
||||||
service:
|
ansible.builtin.file:
|
||||||
|
path: "{{ nginx_etc_dir }}/sites-enabled/{{ item | nginx_site_name }}"
|
||||||
|
state: absent
|
||||||
|
loop: "{{ acme_create }}"
|
||||||
|
when: fake_site.changed
|
||||||
|
|
||||||
|
- name: SERVICE | Restart nginx
|
||||||
|
ansible.builtin.service:
|
||||||
name: nginx
|
name: nginx
|
||||||
state: restarted
|
state: restarted
|
||||||
when: fake_site.changed and ansible_virtualization_type != 'docker'
|
when: fake_site.changed and ansible_virtualization_type != 'docker'
|
||||||
|
|
||||||
- name: COMMAND | Restart nginx
|
- name: COMMAND | Restart nginx
|
||||||
command: service nginx restart
|
ansible.builtin.command: service nginx restart
|
||||||
|
args:
|
||||||
|
warn: false
|
||||||
when: fake_site.changed and ansible_virtualization_type == 'docker'
|
when: fake_site.changed and ansible_virtualization_type == 'docker'
|
||||||
|
|
||||||
- name: SHELL | Get certificates
|
- name: COMMAND | 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 %}'
|
ansible.builtin.command: |
|
||||||
|
{{ nginx_acmesh_bin }}
|
||||||
|
--home {{ nginx_acmesh_dir }}
|
||||||
|
--issue{% for s in nginx_sites | nginx_search_by_ssl_name(item.name) | nginx_all_site_names %} -d {{ s }}{% endfor %}
|
||||||
|
--nginx
|
||||||
|
{% if nginx_acmesh_test %}--test --log{% endif %}
|
||||||
args:
|
args:
|
||||||
creates: "/root/.acme.sh/{{ item | nginx_site_name }}/{{ item | nginx_site_name }}.key"
|
creates: "{{ nginx_acmesh_dir }}/{{ item | nginx_site_name }}/fullchain.cer"
|
||||||
with_items: "{{ acme_create }}"
|
loop: "{{ acme_create }}"
|
||||||
register: acme_get
|
register: acme_get
|
||||||
failed_when: acme_get.rc != 0 and acme_get.rc != 2
|
failed_when: acme_get.rc != 0 and acme_get.rc != 2
|
||||||
no_log: not nginx_debug_role
|
no_log: "{{ not nginx_debug_role }}"
|
||||||
|
|
||||||
- name: FILE | Create SSL dir per site
|
- name: FILE | Create SSL dir per site
|
||||||
file:
|
ansible.builtin.file:
|
||||||
path: "{{ nginx_ssl_dir }}/{{ item | nginx_site_name }}"
|
path: "{{ nginx_ssl_dir }}/{{ item | nginx_site_name }}"
|
||||||
with_items: "{{ acme_create }}"
|
loop: "{{ acme_create }}"
|
||||||
|
|
||||||
- name: SHELL | Install certificates
|
- name: COMMAND | 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'
|
ansible.builtin.command: |
|
||||||
|
{{ nginx_acmesh_bin }}
|
||||||
|
--home {{ nginx_acmesh_dir }}
|
||||||
|
--install-cert -d {{ nginx_sites | nginx_search_by_ssl_name(item | nginx_site_name) | nginx_site_name }}
|
||||||
|
--fullchain-file {{ item | nginx_cert_path(nginx_ssl_dir) }}
|
||||||
|
--key-file {{ item | nginx_key_path(nginx_ssl_dir) }}
|
||||||
|
--reloadcmd "service nginx reload"
|
||||||
args:
|
args:
|
||||||
creates: "{{ nginx_ssl_dir }}/{{ item | nginx_site_name }}/{{ item | nginx_site_name }}.key"
|
creates: "{{ item | nginx_cert_path(nginx_ssl_dir) }}"
|
||||||
with_items: "{{ nginx_ssl_pairs }}"
|
loop: "{{ nginx_ssl_pairs }}"
|
||||||
when: item.acme is defined and item.acme
|
when: item.acme is defined and item.acme
|
||||||
notify: restart nginx
|
notify: restart nginx
|
||||||
|
|
||||||
- name: FILE | Delete fake sites
|
rescue:
|
||||||
file:
|
|
||||||
|
- name: FAIL | Explicit
|
||||||
|
ansible.builtin.fail:
|
||||||
|
msg: "Something is bad... Auto crash!"
|
||||||
|
|
||||||
|
always:
|
||||||
|
|
||||||
|
- name: FILE | Delete fake sites
|
||||||
|
ansible.builtin.file:
|
||||||
path: "{{ nginx_etc_dir }}/conf.d/FAKESITE_{{ item | nginx_site_name }}.conf"
|
path: "{{ nginx_etc_dir }}/conf.d/FAKESITE_{{ item | nginx_site_name }}.conf"
|
||||||
state: absent
|
state: absent
|
||||||
with_items: "{{ acme_create }}"
|
loop: "{{ acme_create }}"
|
||||||
|
notify: restart nginx
|
||||||
|
|
||||||
|
- name: META | Flush handlers
|
||||||
|
ansible.builtin.meta: flush_handlers
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
- name: INCLUDE | standard.yml
|
- name: IMPORT_TASKS | standard.yml
|
||||||
include: standard.yml
|
import_tasks: standard.yml
|
||||||
|
|
||||||
- name: INCLUDE | acme.yml
|
- name: IMPORT_TASKS | acme.yml
|
||||||
include: acme.yml
|
import_tasks: acme.yml
|
||||||
when: nginx_acmesh
|
when: nginx_acmesh
|
||||||
|
|||||||
@@ -1,53 +1,82 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
- name: COMMAND | Generate DH file
|
- block:
|
||||||
command: openssl dhparam -out {{ nginx_dh_path }} {{ nginx_dh_length }}
|
|
||||||
args:
|
- name: STAT | Get info about DH file
|
||||||
creates: "{{ nginx_dh_path }}"
|
ansible.builtin.stat:
|
||||||
when: nginx_dh is not string
|
path: "{{ nginx_dh_path }}"
|
||||||
|
get_checksum: false
|
||||||
|
register: stat_dh_file
|
||||||
|
|
||||||
|
- name: SHELL | Get info about DH file
|
||||||
|
ansible.builtin.shell: openssl dhparam -in {{ nginx_dh_path }} -text -noout 2>&1 | awk '/DH Parameters/ { print substr($3, 2) }'
|
||||||
|
changed_when: false
|
||||||
|
register: dh_info
|
||||||
|
when: stat_dh_file.stat.exists
|
||||||
|
|
||||||
|
- name: COMMAND | Generate DH file
|
||||||
|
ansible.builtin.command: openssl dhparam -out {{ nginx_dh_path }} {{ nginx_dh_length }}
|
||||||
|
when: not stat_dh_file.stat.exists or (dh_info.stdout | int != nginx_dh_length | int)
|
||||||
notify: restart nginx
|
notify: restart nginx
|
||||||
async: 1000
|
|
||||||
register: dh
|
when: nginx_dh is not string
|
||||||
|
|
||||||
- name: COPY | Deploy DH file from vars
|
- name: COPY | Deploy DH file from vars
|
||||||
copy:
|
ansible.builtin.copy:
|
||||||
content: "{{ nginx_dh }}"
|
content: "{{ nginx_dh }}"
|
||||||
dest: "{{ nginx_dh_path }}"
|
dest: "{{ nginx_dh_path }}"
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: 0640
|
||||||
when: nginx_dh is string
|
when: nginx_dh is string
|
||||||
notify: restart nginx
|
notify: restart nginx
|
||||||
|
|
||||||
- name: FILE | Create SSL directories
|
- name: FILE | Create SSL directories
|
||||||
file:
|
ansible.builtin.file:
|
||||||
path: "{{ nginx_ssl_dir + '/' + item.name }}"
|
path: "{{ item | nginx_ssl_dir(nginx_ssl_dir) }}"
|
||||||
state: directory
|
state: directory
|
||||||
with_items: "{{ nginx_ssl_pairs }}"
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: 0750
|
||||||
|
loop: "{{ nginx_ssl_pairs }}"
|
||||||
when: item.dest_key is not defined or item.dest_cert is not defined
|
when: item.dest_key is not defined or item.dest_cert is not defined
|
||||||
no_log: not nginx_debug_role
|
no_log: "{{ not nginx_debug_role }}"
|
||||||
|
|
||||||
- name: COPY | Deploy SSL keys
|
- name: COPY | Deploy SSL keys
|
||||||
copy:
|
ansible.builtin.copy:
|
||||||
content: "{{ item.key }}"
|
content: "{{ item.key }}"
|
||||||
dest: "{{ nginx_ssl_dir + '/' + item.name + '/' + item.name + '.key' if item.dest_key is not defined else item.dest_key }}"
|
dest: "{{ item | nginx_key_path(nginx_ssl_dir) }}"
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
mode: 0640
|
mode: 0640
|
||||||
with_items: "{{ nginx_ssl_pairs }}"
|
loop: "{{ nginx_ssl_pairs }}"
|
||||||
when: item.key is defined
|
when: item.key is defined
|
||||||
notify: restart nginx
|
notify: restart nginx
|
||||||
no_log: not nginx_debug_role
|
no_log: "{{ not nginx_debug_role }}"
|
||||||
|
|
||||||
- name: COPY | Deploy SSL certs
|
- name: COPY | Deploy SSL certs
|
||||||
copy:
|
ansible.builtin.copy:
|
||||||
content: "{{ item.cert }}"
|
content: "{{ item.cert }}"
|
||||||
dest: "{{ nginx_ssl_dir + '/' + item.name + '/' + item.name + '.crt' if item.dest_cert is not defined else item.dest_cert }}"
|
dest: "{{ item | nginx_cert_path(nginx_ssl_dir) }}"
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
mode: 0644
|
mode: 0644
|
||||||
with_items: "{{ nginx_ssl_pairs }}"
|
loop: "{{ nginx_ssl_pairs }}"
|
||||||
when: item.cert is defined
|
when: item.cert is defined
|
||||||
notify: restart nginx
|
notify: restart nginx
|
||||||
no_log: not nginx_debug_role
|
no_log: "{{ not nginx_debug_role }}"
|
||||||
|
|
||||||
- name: Check DH command status
|
- name: COMMAND | Create self-signed certificates
|
||||||
async_status:
|
ansible.builtin.command: |
|
||||||
jid: "{{ dh.ansible_job_id }}"
|
openssl req
|
||||||
register: job_result
|
-new -newkey rsa:2048 -sha256 -days 3650 -nodes -x509
|
||||||
until: job_result.finished
|
-subj '/CN={{ item | nginx_site_name }}'
|
||||||
retries: 30
|
-keyout {{ item | nginx_key_path(nginx_ssl_dir) }}
|
||||||
when: not ansible_check_mode and nginx_dh is not string
|
-out {{ item | nginx_cert_path(nginx_ssl_dir) }}
|
||||||
|
args:
|
||||||
|
chdir: "{{ item | nginx_ssl_dir(nginx_ssl_dir) }}"
|
||||||
|
creates: "{{ '/tmp/dummy' if item.force is defined and item.force else item | nginx_cert_path(nginx_ssl_dir) }}"
|
||||||
|
loop: "{{ nginx_ssl_pairs }}"
|
||||||
|
when: item.self_signed is defined
|
||||||
|
notify: restart nginx
|
||||||
|
no_log: "{{ not nginx_debug_role }}"
|
||||||
|
|||||||
@@ -1,30 +1,29 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
- name: TEMPLATE | Deploy PHP upstream to Nginx
|
- name: TEMPLATE | Deploy PHP upstream to Nginx
|
||||||
template:
|
ansible.builtin.template:
|
||||||
src: "etc/nginx/conf.d/php.conf.j2"
|
src: "etc/nginx/conf.d/php.conf.j2"
|
||||||
dest: "{{ nginx_etc_dir }}/conf.d/php.conf"
|
dest: "{{ nginx_etc_dir }}/conf.d/php.conf"
|
||||||
when: nginx_php | length > 0
|
mode: 0644
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
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:
|
ansible.builtin.template:
|
||||||
src: "etc/nginx/conf.d/_upstream.conf.j2"
|
src: "etc/nginx/conf.d/_upstream.conf.j2"
|
||||||
dest: "{{ nginx_etc_dir }}/conf.d/upstream-{{ item.name }}.conf"
|
dest: "{{ nginx_etc_dir }}/conf.d/upstream-{{ item.name }}.conf"
|
||||||
with_items: "{{ nginx_upstreams }}"
|
mode: 0644
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
loop: "{{ nginx_upstreams }}"
|
||||||
when: item.state is not defined or item.state == 'present'
|
when: item.state is not defined or item.state == 'present'
|
||||||
notify: reload nginx
|
notify: reload nginx
|
||||||
|
|
||||||
- name: FILE | Delete other upstreams
|
- name: FILE | Delete other upstreams
|
||||||
file:
|
ansible.builtin.file:
|
||||||
path: "{{ nginx_etc_dir }}/conf.d/upstream-{{ item.name }}.conf"
|
path: "{{ nginx_etc_dir }}/conf.d/upstream-{{ item.name }}.conf"
|
||||||
state: absent
|
state: absent
|
||||||
with_items: "{{ nginx_upstreams }}"
|
loop: "{{ nginx_upstreams }}"
|
||||||
when: item.state is defined and item.state == 'absent'
|
when: item.state is defined and item.state == 'absent'
|
||||||
notify: reload nginx
|
notify: reload nginx
|
||||||
|
|||||||
18
templates/etc/nginx/conf.d/FAKESITE.conf.j2
Normal file
18
templates/etc/nginx/conf.d/FAKESITE.conf.j2
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
{% set site = nginx_sites | nginx_search_by_ssl_name(item.name) %}
|
||||||
|
{% set __listen = item.listen | default(nginx_default_listen) %}
|
||||||
|
{% set __listen_proxy_protocol = item.listen_proxy_protocol | default(nginx_default_listen_proxy_protocol) %}
|
||||||
|
|
||||||
|
server {
|
||||||
|
{% for port in __listen %}
|
||||||
|
listen {{ port }};
|
||||||
|
{% endfor %}
|
||||||
|
{% for port in __listen_proxy_protocol %}
|
||||||
|
listen {{ port }} proxy_protocol;
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
server_name {{ site | nginx_all_site_names | join(" ") }};
|
||||||
|
|
||||||
|
location / {
|
||||||
|
return 503;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
{%- macro s(key, value, is_bool, min_version) %}
|
{%- macro s(key, value, is_bool, min_version) %}
|
||||||
{% if nginx_version.stdout | version_compare(min_version, 'ge') %}
|
{% if nginx_version.stdout is version(min_version, 'ge') %}
|
||||||
{% if is_bool and value %} {{ key }}{% elif not is_bool %} {{ key }}={{ value }}{% endif %}
|
{% if is_bool and value %} {{ key }}{% elif not is_bool %} {{ key }}={{ value }}{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{%- endmacro -%}
|
{%- endmacro -%}
|
||||||
|
|||||||
@@ -3,18 +3,27 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
{% for php in nginx_php %}
|
{% for php in nginx_php %}
|
||||||
upstream {{ php.upstream_name | default((php.version | php_default_upstream_name)) }} {
|
upstream {{ php.upstream_name }} {
|
||||||
{% for sock in php.sockets | default([]) %}
|
{% for sock in php.sockets | default([]) %}
|
||||||
{% if sock.host is defined %}
|
{% 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') }};
|
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 %}
|
{% else %}
|
||||||
server unix:{{ sock.unix | default((php.version | php_default_upstream_socket)) }} weight={{ sock.weight | default('1') }};
|
server unix:{{ sock.unix }} weight={{ sock.weight | default('1') }};
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% else %}
|
|
||||||
server unix:{{ php.version | php_default_upstream_socket }} weight=1;
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
}
|
}
|
||||||
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
{% if ansible_local.hanxhx_php.fpm_pool is defined%}
|
||||||
|
# -------------------------------------------------------
|
||||||
|
# Auto-detected PHP config for HanXHX.php ansible role
|
||||||
|
# -------------------------------------------------------
|
||||||
|
|
||||||
|
{% for php in ansible_local.hanxhx_php.fpm_pool %}
|
||||||
|
upstream {{ php.name }} {
|
||||||
|
server {% if php.listen.startswith('/') %}unix:{{ php.listen }}{% else %}{{ php.listen }}{% endif %};
|
||||||
|
}
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
# vim:filetype=nginx
|
# vim:filetype=nginx
|
||||||
|
|||||||
@@ -3,10 +3,10 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
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_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_protocols TLSv1.1 TLSv1.2{% if nginx_version.stdout is version('1.13.0', 'ge') %} TLSv1.3{% endif %};
|
||||||
ssl_prefer_server_ciphers on;
|
ssl_prefer_server_ciphers on;
|
||||||
ssl_session_cache shared:SSL:10m;
|
ssl_session_cache shared:SSL:10m;
|
||||||
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains"{% if nginx_version.stdout | version_compare('1.7.5', 'ge') %} always{% endif %};
|
ssl_session_tickets off;
|
||||||
ssl_stapling on;
|
ssl_stapling on;
|
||||||
ssl_stapling_verify on;
|
ssl_stapling_verify on;
|
||||||
resolver {{ nginx_resolver_hosts | join(' ') }} valid={{ nginx_resolver_valid }};
|
resolver {{ nginx_resolver_hosts | join(' ') }} valid={{ nginx_resolver_valid }};
|
||||||
|
|||||||
@@ -2,11 +2,13 @@
|
|||||||
# {{ ansible_managed }}
|
# {{ ansible_managed }}
|
||||||
#
|
#
|
||||||
|
|
||||||
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
|
ssl_ciphers "ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384";
|
||||||
ssl_protocols TLSv1 TLSv1.1 TLSv1.2{% if nginx_version.stdout | version_compare('1.13.0', 'ge') %} TLSv1.3{% endif %};
|
ssl_protocols TLSv1.2{% if nginx_version.stdout is version('1.13.0', 'ge') %} TLSv1.3{% endif %};
|
||||||
ssl_prefer_server_ciphers on;
|
ssl_prefer_server_ciphers on;
|
||||||
|
ssl_ecdh_curve secp384r1;
|
||||||
|
ssl_session_timeout 10m;
|
||||||
ssl_session_cache shared:SSL:10m;
|
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_session_tickets off;
|
||||||
ssl_stapling on;
|
ssl_stapling on;
|
||||||
ssl_stapling_verify on;
|
ssl_stapling_verify on;
|
||||||
resolver {{ nginx_resolver_hosts | join(' ') }} valid={{ nginx_resolver_valid }};
|
resolver {{ nginx_resolver_hosts | join(' ') }} valid={{ nginx_resolver_valid }};
|
||||||
|
|||||||
@@ -5,9 +5,7 @@
|
|||||||
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;
|
include {{ nginx_etc_dir }}/modules-enabled/*.conf;
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
events {
|
events {
|
||||||
worker_connections {{ nginx_events_worker_connections }};
|
worker_connections {{ nginx_events_worker_connections }};
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
{% 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,13 +1,39 @@
|
|||||||
{% set __proto = item.proto | default(['http']) %}
|
{% set __proto = item.proto | default(['http']) %}
|
||||||
{% set __main_name = item | nginx_site_filename %}
|
{% set __main_name = item | nginx_site_name %}
|
||||||
{% set __listen = item.listen | default([80]) %}
|
{% set __listen = item.listen | default(nginx_default_listen) %}
|
||||||
{% set __listen_ssl = item.listen_ssl | default([443]) %}
|
{% set __listen_ssl = item.listen_ssl | default(nginx_default_listen_ssl) %}
|
||||||
{% set __http_proxy_protocol_port = item.http_proxy_protocol_port | default([]) %}
|
{% set __listen_proxy_protocol = item.listen_proxy_protocol | default(nginx_default_listen_proxy_protocol) %}
|
||||||
{% set __https_proxy_protocol_port = item.https_proxy_protocol_port | default([]) %}
|
{% set __listen_proxy_protocol_ssl = item.listen_proxy_protocol_ssl | default(nginx_default_listen_proxy_protocol_ssl) %}
|
||||||
{% set __location = item.location | default({}) %}
|
{% set __location = item.location | default({}) %}
|
||||||
|
{% set __location_before = item.location_before | default({}) %}
|
||||||
{% set __headers = item.headers | default(nginx_servers_default_headers) %}
|
{% 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 __ssl_name = item.ssl_name | default(__main_name) %}
|
||||||
{% set __location_order = item.location_order | default(__location.keys()) %}
|
{% set __location_order = item.location_order | default(__location.keys()) %}
|
||||||
|
{% set __location_order_before = item.location_order_before | default(__location_before.keys()) %}
|
||||||
|
{% set __http2 = nginx_auto_config_httpv2 and 'http_v2' in nginx_modules %}
|
||||||
|
{% macro listen_http() %}
|
||||||
|
{% endmacro %}
|
||||||
|
{% macro server_name(name) %}
|
||||||
|
{% if name is string %}{{ name }}{% else %}{{ name | join(" ") }}{% endif %}
|
||||||
|
{% endmacro %}
|
||||||
|
{% macro locations(list, order) %}
|
||||||
|
{% if order | length > 0 %}
|
||||||
|
# --> Custom locations
|
||||||
|
{% for location in order %}
|
||||||
|
location {{ location }} {
|
||||||
|
{% set opts = list[location] %}
|
||||||
|
{% for opt in opts %}
|
||||||
|
{% if opt.htpasswd is defined %}
|
||||||
|
{{ htpasswd(opt.htpasswd, 2) }}
|
||||||
|
{% else %}
|
||||||
|
{{ opt }}
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
}
|
||||||
|
{% endfor %}
|
||||||
|
# <-- Custom locations
|
||||||
|
{% endif %}
|
||||||
|
{% endmacro %}
|
||||||
{% macro htpasswd(htpasswd_name, indent=1) -%}
|
{% macro htpasswd(htpasswd_name, indent=1) -%}
|
||||||
{%- if htpasswd_name != false %}
|
{%- if htpasswd_name != false %}
|
||||||
{%- for ht in nginx_htpasswd if ht.name == htpasswd_name %}
|
{%- for ht in nginx_htpasswd if ht.name == htpasswd_name %}
|
||||||
@@ -17,17 +43,20 @@
|
|||||||
{%- endif %}
|
{%- endif %}
|
||||||
{%- endmacro %}
|
{%- endmacro %}
|
||||||
{% macro ssl(ssl_name) %}
|
{% macro ssl(ssl_name) %}
|
||||||
{% for sn in nginx_ssl_pairs if sn.name == ssl_name %}
|
{% for sn in nginx_ssl_pairs if (sn.name is defined and (sn | nginx_site_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 {{ sn | nginx_cert_path(nginx_ssl_dir) }};
|
||||||
ssl_certificate_key {{ nginx_ssl_dir + '/' + ssl_name + '/' + ssl_name + '.key' if sn.dest_key is not defined else sn.dest_key }};
|
ssl_certificate_key {{ sn | nginx_key_path(nginx_ssl_dir) }};
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{%- endmacro %}
|
{%- endmacro %}
|
||||||
{% macro httpsredirect(name) %}
|
{% macro httpsredirect(name) %}
|
||||||
server {
|
server {
|
||||||
{% for port in __listen %}
|
{% for port in __listen %}
|
||||||
listen {{ port }}{% if port | int in __http_proxy_protocol_port %} proxy_protocol{% endif %};
|
listen {{ port }};
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
server_name {{ name }};
|
{% for port in __listen_proxy_protocol %}
|
||||||
|
listen {{ port }} proxy_protocol;
|
||||||
|
{% endfor %}
|
||||||
|
server_name {{ server_name(name) }};
|
||||||
location / {
|
location / {
|
||||||
return 301 https://{{ name }}{% if '443' not in __listen_ssl and 443 not in __listen_ssl %}:{{ __listen_ssl[0] }}{% endif %}$request_uri;
|
return 301 https://{{ name }}{% if '443' not in __listen_ssl and 443 not in __listen_ssl %}:{{ __listen_ssl[0] }}{% endif %}$request_uri;
|
||||||
}
|
}
|
||||||
@@ -44,24 +73,31 @@ server {
|
|||||||
server {
|
server {
|
||||||
{% if 'http' in __proto %}
|
{% if 'http' in __proto %}
|
||||||
{% for port in __listen %}
|
{% for port in __listen %}
|
||||||
listen {{ port }}{% if nginx_default_site == __main_name %} default_server{% endif %}{% if port | int in __http_proxy_protocol_port %} proxy_protocol{% endif %};
|
listen {{ port }}{% if nginx_default_site == __main_name %} default_server{% endif %};
|
||||||
|
{% endfor %}
|
||||||
|
{% for port in __listen_proxy_protocol %}
|
||||||
|
listen {{ port }}{% if nginx_default_site == __main_name %} default_server{% endif %} proxy_protocol;
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if 'https' in __proto %}
|
{% if 'https' in __proto %}
|
||||||
{% for port in __listen_ssl %}
|
{% for port in __listen_ssl %}
|
||||||
listen {{ port }}{% if nginx_default_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 %};
|
listen {{ port }}{% if nginx_default_site_ssl == __main_name %} default_server{% endif %} ssl{% if __http2 %} http2{% endif %};
|
||||||
|
{% endfor %}
|
||||||
|
{% for port in __listen_proxy_protocol_ssl %}
|
||||||
|
listen {{ port }}{% if nginx_default_site_ssl == __main_name %} default_server{% endif %} ssl{% if __http2 %} http2{% endif %} proxy_protocol;
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{{ ssl(__ssl_name) }}
|
{{ ssl(__ssl_name) }}
|
||||||
{% if item.ssl_template is not defined or item.ssl_template != false %}
|
{% if item.ssl_template is not defined or item.ssl_template != false %}
|
||||||
include {{ nginx_helper_dir + '/ssl-' + item.ssl_template | default('strong') }};
|
include {{ nginx_helper_dir + '/ssl-' + item.ssl_template | default('strong') }};
|
||||||
|
add_header Strict-Transport-Security "{{ item.hsts | default(nginx_default_hsts) }}" always;
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
server_name {% if item.name is string %}{{ item.name }}{% else %}{{ "\n\t\t" }}{{ item.name | join("\n\t\t") }}{% endif %};
|
server_name {{ server_name(item.name) }};
|
||||||
{% block root %}
|
{% block root %}
|
||||||
{% if item.root is defined %}
|
{% if item.root is defined %}
|
||||||
root {{ item.root }};
|
root {{ item.root }};
|
||||||
{% else %}
|
{% else %}
|
||||||
root {{ nginx_root }}/{{ __main_name }}/public;
|
root {{ nginx_root }}/{{ item | nginx_site_filename }}/public;
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block template_index %}
|
{% block template_index %}
|
||||||
@@ -82,16 +118,18 @@ server {
|
|||||||
|
|
||||||
{% block template_headers %}
|
{% block template_headers %}
|
||||||
# --> Custom headers
|
# --> Custom headers
|
||||||
{% for key, value in __headers.iteritems() %}
|
{% for key, value in __headers.items() %}
|
||||||
add_header {{ key }} "{{ value | replace(' always', '') }}"{% if nginx_version.stdout | version_compare('1.7.5', 'ge') and ' always' in value %} always{% endif %};
|
add_header {{ key }} "{{ value | regex_replace('\s+always$', '') }}"{% if value | regex_search('\s+always$') %} always{% endif %};
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
# <-- Custom headers
|
# <-- Custom headers
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% if not __location.has_key('/') %}
|
{{ locations(__location_before, __location_order_before) }}
|
||||||
|
|
||||||
|
{% if not '/' in __location %}
|
||||||
location / {
|
location / {
|
||||||
{% block template_try_files %}
|
{% block template_try_files %}
|
||||||
try_files {{ override_try_files | default('$uri $uri/ =404') }};
|
try_files {{ item.override_try_files | default('$uri $uri/ =404') }};
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
}
|
}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@@ -101,19 +139,7 @@ server {
|
|||||||
{% block template_custom_location %}
|
{% block template_custom_location %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% if __location_order | length > 0 %}
|
{{ locations(__location, __location_order) }}
|
||||||
# --> Custom locations
|
|
||||||
{% for location in __location_order %}
|
|
||||||
location {{ location }} {
|
|
||||||
{% set opts = __location[location] %}
|
|
||||||
{% for opt in opts %}
|
|
||||||
{% if opt.htpasswd is defined %}{{ htpasswd(opt.htpasswd, 2) }}{% else %}
|
|
||||||
{{ opt }}
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
|
||||||
}
|
|
||||||
{% endfor %} # <-- Custom locations
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% block template_local_content %}
|
{% block template_local_content %}
|
||||||
{% if item.manage_local_content is not defined or item.manage_local_content %}
|
{% if item.manage_local_content is not defined or item.manage_local_content %}
|
||||||
@@ -127,7 +153,7 @@ server {
|
|||||||
log_not_found off;
|
log_not_found off;
|
||||||
}
|
}
|
||||||
|
|
||||||
location ~* \.(txt|js|css|png|jpe?g|gif|ico|svg)$ {
|
location ~* \.(txt|js|css|png|jpe?g|gif|ico|svg|(o|t)tf|woff2?|eot)$ {
|
||||||
expires 30d;
|
expires 30d;
|
||||||
log_not_found off;
|
log_not_found off;
|
||||||
}
|
}
|
||||||
@@ -169,26 +195,34 @@ server {
|
|||||||
#
|
#
|
||||||
server {
|
server {
|
||||||
{% for port in __listen %}
|
{% for port in __listen %}
|
||||||
listen {{ port }}{% if port | int in __http_proxy_protocol_port %} proxy_protocol{% endif %};
|
listen {{ port }};
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
server_name {% if item.redirect_from is string %}{{ item.redirect_from }}{% else %}{{ "\n\t\t" }}{{ item.redirect_from | join("\n\t\t") }}{% endif %};
|
{% for port in __listen_proxy_protocol %}
|
||||||
|
listen {{ port }} proxy_protocol;
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
server_name {{ server_name(item.redirect_from) }};
|
||||||
location / {
|
location / {
|
||||||
return 301 $scheme://{{ item.name if item.name is string else item.name[0] }}$request_uri;
|
return 301 $scheme://{{ __main_name }}$request_uri;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{% if 'https' in __proto %}
|
{% if 'https' in __proto %}
|
||||||
server {
|
server {
|
||||||
{% for port in __listen_ssl %}
|
{% 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 %};
|
listen {{ port }} ssl{% if __http2 %} http2{% endif %};
|
||||||
|
{% endfor %}
|
||||||
|
{% for port in __listen_proxy_protocol_ssl %}
|
||||||
|
listen {{ port }} ssl{% if __http2 %} http2{% endif %} proxy_protocol;
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{{ ssl(__ssl_name) }}
|
{{ ssl(__ssl_name) }}
|
||||||
{% if item.ssl_template is not defined or item.ssl_template != false %}
|
{% if item.ssl_template is not defined or item.ssl_template != false %}
|
||||||
include {{ nginx_helper_dir + '/ssl-' + item.ssl_template | default('strong') }};
|
include {{ nginx_helper_dir + '/ssl-' + item.ssl_template | default('strong') }};
|
||||||
|
add_header Strict-Transport-Security "{{ item.hsts | default(nginx_default_hsts) }}" always;
|
||||||
{% endif %}
|
{% endif %}
|
||||||
server_name {% if item.redirect_from is string %}{{ item.redirect_from }}{% else %}{{ "\n\t\t" }}{{ item.redirect_from | join("\n\t\t") }}{% endif %};
|
server_name {{ server_name(item.redirect_from) }};
|
||||||
location / {
|
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;
|
return 301 https://{{ __main_name }}{% if '443' not in __listen_ssl and 443 not in __listen_ssl %}:{{ __listen_ssl[0] }}{% endif %}$request_uri;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -1,59 +0,0 @@
|
|||||||
{% 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,28 +1,16 @@
|
|||||||
{% 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/ =404') }};
|
try_files {{ item.override_try_files | default('$uri $uri/ =404') }};
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block template_upstream_location %}
|
{% block template_upstream_location %}
|
||||||
location ~ \.php$ {
|
location ~ \.php$ {
|
||||||
# {{ php_info }}
|
fastcgi_pass {{ item.php_upstream }};
|
||||||
fastcgi_pass {{ php_upstream }};
|
|
||||||
fastcgi_index index.php;
|
fastcgi_index index.php;
|
||||||
{% if item.upstream_params is defined and item.upstream_params is iterable %}
|
{% if item.upstream_params is defined and item.upstream_params is iterable %}
|
||||||
{% for param in item.upstream_params %}
|
{% for param in item.upstream_params %}
|
||||||
|
|||||||
@@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
{% block template_upstream_location %}
|
{% block template_upstream_location %}
|
||||||
location = /index.php {
|
location = /index.php {
|
||||||
# {{ php_info }}
|
fastcgi_pass {{ item.php_upstream }};
|
||||||
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 %}
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
{% extends "_php.j2" %}
|
{% extends "_php.j2" %}
|
||||||
|
|
||||||
{% block template_try_files %}
|
{% block template_try_files %}
|
||||||
try_files {{ override_try_files | default('$uri $uri/ /index.php') }};
|
try_files {{ item.override_try_files | default('$uri $uri/ /index.php') }};
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block template_upstream_location %}
|
{% block template_upstream_location %}
|
||||||
location = /index.php {
|
location = /index.php {
|
||||||
# {{ php_info }}
|
fastcgi_pass {{ item.php_upstream }};
|
||||||
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 %}
|
||||||
|
|||||||
27
templates/etc/nginx/sites-available/_symfony.j2
Normal file
27
templates/etc/nginx/sites-available/_symfony.j2
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
{% extends "_php.j2" %}
|
||||||
|
|
||||||
|
{% block template_try_files %}
|
||||||
|
try_files $uri /index.php$is_args$args;
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block template_upstream_location %}
|
||||||
|
location /bundles {
|
||||||
|
try_files $uri =404;
|
||||||
|
}
|
||||||
|
|
||||||
|
location ~ ^/index\.php(/|$) {
|
||||||
|
fastcgi_pass {{ item.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;
|
||||||
|
internal;
|
||||||
|
}
|
||||||
|
|
||||||
|
location ~ \.php$ {
|
||||||
|
return 404;
|
||||||
|
}
|
||||||
|
{% endblock %}
|
||||||
@@ -1,20 +1 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
- 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
|
|
||||||
|
|||||||
@@ -1,33 +1 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
#- 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
|
|
||||||
|
|||||||
@@ -6,82 +6,45 @@
|
|||||||
state: present
|
state: present
|
||||||
when: nginx_backports
|
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
|
- name: APT | Install needed packages
|
||||||
apt:
|
apt:
|
||||||
pkg: "{{ item }}"
|
pkg: "{{ packages }}"
|
||||||
update_cache: yes
|
update_cache: true
|
||||||
cache_valid_time: 3600
|
cache_valid_time: 3600
|
||||||
state: present
|
state: present
|
||||||
with_items:
|
vars:
|
||||||
|
packages:
|
||||||
- cron
|
- cron
|
||||||
- curl
|
- curl
|
||||||
- fcgiwrap
|
- daemonize
|
||||||
- jq
|
- jq
|
||||||
- nghttp2
|
- nghttp2
|
||||||
- strace
|
- strace
|
||||||
- vim
|
- vim
|
||||||
- unzip
|
- 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
|
- name: APT | Install PHP
|
||||||
apt:
|
apt:
|
||||||
pkg: "{{ item.version | php_fpm_package }}"
|
pkg: "{{ pkgs }}"
|
||||||
update_cache: yes
|
update_cache: true
|
||||||
cache_valid_time: 3600
|
cache_valid_time: 3600
|
||||||
state: present
|
state: present
|
||||||
with_items: "{{ nginx_php }}"
|
vars:
|
||||||
register: apt_php
|
pkgs:
|
||||||
|
- php-cli
|
||||||
|
- php-fpm
|
||||||
|
|
||||||
- name: SERVICE | Force start fcgiwrap
|
- name: SHELL | Get current PHP version
|
||||||
service:
|
shell: php --version | awk '/^PHP/ { print $2 }' | grep -o -E '^.{3}'
|
||||||
name: "fcgiwrap"
|
changed_when: false
|
||||||
state: started
|
register: cur_php_version
|
||||||
|
|
||||||
# Bypasses Ansible 2.4 issue (cannot use service module)... With service module... php is not really started!
|
# Bypasses Ansible+Docker issue. With service module... php is not really started!
|
||||||
- name: COMMAND | Force start PHP
|
- name: COMMAND | Force start PHP
|
||||||
command: "service {{ item.version | php_fpm_service }} start"
|
command: "service php{{ cur_php_version.stdout }}-fpm start"
|
||||||
with_items: "{{ nginx_php }}"
|
args:
|
||||||
when: apt_php.changed
|
creates: "/run/php/php{{ cur_php_version.stdout }}-fpm.pid"
|
||||||
|
warn: false
|
||||||
|
|
||||||
- name: GET_URL | Download ngrok
|
- name: GET_URL | Download ngrok
|
||||||
get_url:
|
get_url:
|
||||||
@@ -92,8 +55,29 @@
|
|||||||
unarchive:
|
unarchive:
|
||||||
src: "/tmp/ngrok.zip"
|
src: "/tmp/ngrok.zip"
|
||||||
dest: "/tmp"
|
dest: "/tmp"
|
||||||
remote_src: yes
|
remote_src: true
|
||||||
|
|
||||||
- name: SET_FACT | ngrok_path
|
- name: SET_FACT | ngrok_path
|
||||||
set_fact:
|
set_fact:
|
||||||
ngrok_path: '/tmp/ngrok'
|
ngrok_path: '/tmp/ngrok'
|
||||||
|
|
||||||
|
- name: USER | Create PHP User foo
|
||||||
|
user:
|
||||||
|
name: foo
|
||||||
|
system: true
|
||||||
|
|
||||||
|
- name: INCLUDE_ROLE | HanXHX.php
|
||||||
|
include_role:
|
||||||
|
name: "{{ playbook_dir }}/HanXHX.php"
|
||||||
|
vars:
|
||||||
|
php_version: "{{ cur_php_version.stdout }}"
|
||||||
|
php_autoremove_default_pool: false
|
||||||
|
php_fpm_poold:
|
||||||
|
- name: 'hx_unix'
|
||||||
|
user: 'foo'
|
||||||
|
php_value:
|
||||||
|
display_errors: 'Off'
|
||||||
|
php_admin_value:
|
||||||
|
memory_limit: '98M'
|
||||||
|
- name: 'hx_ip'
|
||||||
|
listen: '127.0.0.1:9636'
|
||||||
|
|||||||
@@ -5,42 +5,43 @@
|
|||||||
nginx_pkgng_package: 'nginx-full'
|
nginx_pkgng_package: 'nginx-full'
|
||||||
nginx_user: 'www'
|
nginx_user: 'www'
|
||||||
nginx_php:
|
nginx_php:
|
||||||
- version: '7.2'
|
- upstream_name: 'manual'
|
||||||
|
sockets:
|
||||||
|
- host: '127.0.0.1'
|
||||||
|
port: 9000
|
||||||
|
- upstream_name: 'hx_unix'
|
||||||
|
sockets:
|
||||||
|
- host: '127.0.0.1'
|
||||||
|
port: 9000
|
||||||
|
- upstream_name: 'hx_ip'
|
||||||
sockets:
|
sockets:
|
||||||
- host: '127.0.0.1'
|
- host: '127.0.0.1'
|
||||||
port: 9000
|
port: 9000
|
||||||
nginx_load_modules:
|
|
||||||
- /usr/local/libexec/nginx/ngx_http_geoip_module.so
|
|
||||||
ngrok_path: '/usr/local/bin/ngrok'
|
ngrok_path: '/usr/local/bin/ngrok'
|
||||||
|
|
||||||
- name: PKGNG | Install needed packages
|
- name: PKGNG | Install needed packages
|
||||||
pkgng:
|
pkgng:
|
||||||
pkg: "{{ item }}"
|
pkg: "{{ packages }}"
|
||||||
state: present
|
state: present
|
||||||
with_items:
|
vars:
|
||||||
|
packages:
|
||||||
|
- bash
|
||||||
- curl
|
- curl
|
||||||
- daemonize
|
- daemonize
|
||||||
- fcgiwrap
|
- fcgiwrap
|
||||||
- GeoIP
|
|
||||||
- jq
|
- jq
|
||||||
- nghttp2
|
- nghttp2
|
||||||
- php72
|
- php74
|
||||||
- vim
|
- vim
|
||||||
|
|
||||||
- name: COMMAND | Get geoip database
|
|
||||||
command: geoipupdate.sh
|
|
||||||
args:
|
|
||||||
creates: /usr/local/share/GeoIP/GeoIP.dat
|
|
||||||
|
|
||||||
- name: SERVICE | Force start services
|
- name: SERVICE | Force start services
|
||||||
service:
|
service:
|
||||||
name: "{{ item }}"
|
name: "{{ item }}"
|
||||||
state: started
|
state: started
|
||||||
enabled: yes
|
enabled: true
|
||||||
register: sf
|
register: sf
|
||||||
with_items:
|
loop:
|
||||||
- php-fpm
|
- php-fpm
|
||||||
- fcgiwrap
|
|
||||||
|
|
||||||
- name: STAT | Check ports
|
- name: STAT | Check ports
|
||||||
stat:
|
stat:
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
- name: SHELL | Start ngrok
|
- name: SHELL | Start ngrok
|
||||||
shell: daemonize -l /tmp/ngrok.lock {{ ngrok_path }} http 8888 -bind-tls=false
|
shell: daemonize -l /tmp/ngrok.lock {{ ngrok_path }} http 80 -bind-tls=false
|
||||||
failed_when: false
|
failed_when: false
|
||||||
changed_when: ngrok.stderr.find("Can't lock the lock file") == -1
|
changed_when: ngrok.stderr.find("Can't lock the lock file") == -1
|
||||||
register: ngrok
|
register: ngrok
|
||||||
@@ -13,6 +13,18 @@
|
|||||||
when: ngrok.changed
|
when: ngrok.changed
|
||||||
|
|
||||||
- name: SHELL | Get ngrok public address
|
- 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'
|
shell: set -o pipefail && curl 'http://127.0.0.1:4040/api/tunnels/command_line' 2> /dev/null | jq -r '.public_url' | cut -d '/' -f 3
|
||||||
|
args:
|
||||||
|
executable: /bin/bash
|
||||||
|
warn: false
|
||||||
register: ngrok
|
register: ngrok
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
|
||||||
|
- name: LINEINFILE | Tune vimrc
|
||||||
|
lineinfile:
|
||||||
|
line: "set mouse="
|
||||||
|
dest: "{{ item }}/.vimrc"
|
||||||
|
create: true
|
||||||
|
loop:
|
||||||
|
- /root
|
||||||
|
- /home/vagrant
|
||||||
|
|||||||
16
tests/templates/custom_template.conf.j2
Normal file
16
tests/templates/custom_template.conf.j2
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
# {{ ansible_managed }} - custom template
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
listen 8888 http2;
|
||||||
|
listen 9999 http2 proxy_protocol;
|
||||||
|
server_name {{ item.name }};
|
||||||
|
|
||||||
|
index index.html index.htm;
|
||||||
|
|
||||||
|
root {{ item.root }};
|
||||||
|
|
||||||
|
location / {
|
||||||
|
try_files $uri $uri/ =404;
|
||||||
|
}
|
||||||
|
}
|
||||||
370
tests/test.yml
370
tests/test.yml
@@ -2,38 +2,61 @@
|
|||||||
|
|
||||||
- hosts: all
|
- hosts: all
|
||||||
pre_tasks:
|
pre_tasks:
|
||||||
- name: INCLUDE | Pre_tasks related to OS version
|
|
||||||
include: "includes/pre_{{ ansible_distribution }}.yml"
|
|
||||||
|
|
||||||
- name: INCLUDE | Pre_tasks common
|
- name: INCLUDE_TASKS | Pre_tasks related to OS version
|
||||||
include: "includes/pre_common.yml"
|
ansible.builtin.include_tasks: "includes/pre_{{ ansible_distribution }}.yml"
|
||||||
|
|
||||||
|
- name: IMPORT_TASKS | Pre_tasks common
|
||||||
|
ansible.builtin.import_tasks: "includes/pre_common.yml"
|
||||||
|
|
||||||
- name: FILE | Create an internal SSL dir
|
- name: FILE | Create an internal SSL dir
|
||||||
file:
|
ansible.builtin.file:
|
||||||
path: "{{ int_ansible_ssl_dir }}"
|
path: "{{ int_ansible_ssl_dir }}"
|
||||||
state: directory
|
state: directory
|
||||||
|
mode: 0750
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
|
||||||
- name: COPY | Deploy test certificate
|
- name: COPY | Deploy test certificate
|
||||||
copy:
|
ansible.builtin.copy:
|
||||||
src: "file/test.crt"
|
src: "file/test.crt"
|
||||||
dest: "{{ int_ansible_ssl_dir }}/test.crt"
|
dest: "{{ int_ansible_ssl_dir }}/test.crt"
|
||||||
|
mode: 0640
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
|
||||||
- name: COPY | Deploy test key
|
- name: COPY | Deploy test key
|
||||||
copy:
|
ansible.builtin.copy:
|
||||||
src: "file/test.key"
|
src: "file/test.key"
|
||||||
dest: "{{ int_ansible_ssl_dir }}/test.key"
|
dest: "{{ int_ansible_ssl_dir }}/test.key"
|
||||||
|
mode: 0640
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
|
||||||
- name: LINEINFILE | Add all hosts in /etc/hosts
|
- name: COPY | Add all hosts in /etc/hosts
|
||||||
lineinfile:
|
ansible.builtin.copy:
|
||||||
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 %}"
|
content: |
|
||||||
regexp: '^127\.0\.0\.1'
|
127.0.0.1 localhost
|
||||||
|
{% for s in nginx_sites %}
|
||||||
|
{% if s.name is string %}
|
||||||
|
127.0.0.1 {{ s.name }}
|
||||||
|
{% else %}
|
||||||
|
127.0.0.1 {% for n in s.name %}{{ n }} {% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
{% if s.redirect_from is defined %}
|
||||||
|
127.0.0.1 {% for rf in s.redirect_from %}{{ rf }} {% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
dest: "/etc/hosts"
|
dest: "/etc/hosts"
|
||||||
unsafe_writes: yes
|
mode: 0644
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
unsafe_writes: true
|
||||||
|
|
||||||
vars:
|
vars:
|
||||||
# Internal vars
|
# Internal vars
|
||||||
int_ansible_ssl_dir: '/etc/ansible-ssl'
|
int_ansible_ssl_dir: '/etc/ansible-ssl'
|
||||||
# Role vars
|
# Role vars
|
||||||
nginx_worker_processes: 1 # Ansible+FreeBSD can't detect CPU number
|
nginx_worker_processes: 1 # Ansible+FreeBSD can't detect CPU number
|
||||||
nginx_apt_package: 'nginx-extras'
|
nginx_apt_package: 'nginx-extras'
|
||||||
nginx_module_packages: ['libnginx-mod-http-headers-more-filter']
|
nginx_module_packages: ['libnginx-mod-http-headers-more-filter']
|
||||||
@@ -60,11 +83,6 @@
|
|||||||
state: 'absent'
|
state: 'absent'
|
||||||
- name: 'hanx'
|
- name: 'hanx'
|
||||||
password: 'qwerty'
|
password: 'qwerty'
|
||||||
- name: 'nagios'
|
|
||||||
description: 'Please login to Nagios!'
|
|
||||||
users:
|
|
||||||
- name: 'nagiosadmin'
|
|
||||||
password: 'nagios'
|
|
||||||
- name: 'deleteme'
|
- name: 'deleteme'
|
||||||
description: 'Please login!'
|
description: 'Please login!'
|
||||||
users: []
|
users: []
|
||||||
@@ -74,8 +92,12 @@
|
|||||||
nginx_ssl_pairs:
|
nginx_ssl_pairs:
|
||||||
- name: '{{ ngrok.stdout }}'
|
- name: '{{ ngrok.stdout }}'
|
||||||
acme: true
|
acme: true
|
||||||
acme_port: 8888
|
- name: 'test-ssl-selfsigned.local'
|
||||||
- name: 'test-ssl-predeployed.local'
|
self_signed: true
|
||||||
|
force: false
|
||||||
|
- name:
|
||||||
|
- 'test-ssl-predeployed.local'
|
||||||
|
- 'test-multiple-name.local' # Hack: tests for acme with multiple name, without using acme
|
||||||
dest_key: "{{ int_ansible_ssl_dir }}/test.key"
|
dest_key: "{{ int_ansible_ssl_dir }}/test.key"
|
||||||
dest_cert: "{{ int_ansible_ssl_dir }}/test.crt"
|
dest_cert: "{{ int_ansible_ssl_dir }}/test.crt"
|
||||||
- name: 'test-ssl.local'
|
- name: 'test-ssl.local'
|
||||||
@@ -136,7 +158,7 @@
|
|||||||
- ' DZ no;'
|
- ' DZ no;'
|
||||||
- ' TN no;'
|
- ' TN no;'
|
||||||
- '}'
|
- '}'
|
||||||
nginx_default_site: 'first-test'
|
nginx_default_site: 'test.local'
|
||||||
nginx_default_site_ssl: 'test-ssl-predeployed.local'
|
nginx_default_site_ssl: 'test-ssl-predeployed.local'
|
||||||
nginx_sites:
|
nginx_sites:
|
||||||
- name:
|
- name:
|
||||||
@@ -144,8 +166,8 @@
|
|||||||
- 'test-alias.local'
|
- 'test-alias.local'
|
||||||
- 'test2-alias.local'
|
- 'test2-alias.local'
|
||||||
template: '_base'
|
template: '_base'
|
||||||
filename : 'first-test'
|
filename: 'first-test'
|
||||||
override_try_files: '$uri $uri index.htm index.html'
|
override_try_files: '$uri/ $uri =404'
|
||||||
headers:
|
headers:
|
||||||
'X-Frame-Options': 'deny always'
|
'X-Frame-Options': 'deny always'
|
||||||
'X-ansible-default': '1'
|
'X-ansible-default': '1'
|
||||||
@@ -165,9 +187,10 @@
|
|||||||
- 'deny all;'
|
- 'deny all;'
|
||||||
- name: 'test-htpasswd.local'
|
- name: 'test-htpasswd.local'
|
||||||
template: '_base'
|
template: '_base'
|
||||||
location:
|
location_before:
|
||||||
'/hello':
|
'/hello':
|
||||||
- htpasswd: 'hello'
|
- htpasswd: 'hello'
|
||||||
|
location:
|
||||||
'/public':
|
'/public':
|
||||||
- htpasswd: false
|
- htpasswd: false
|
||||||
use_error_log: true
|
use_error_log: true
|
||||||
@@ -176,22 +199,24 @@
|
|||||||
htpasswd: 'hello'
|
htpasswd: 'hello'
|
||||||
- name: 'test-location.local'
|
- name: 'test-location.local'
|
||||||
template: '_base'
|
template: '_base'
|
||||||
|
location_before:
|
||||||
|
'/b':
|
||||||
|
- 'alias /var/tmp;'
|
||||||
|
'/c':
|
||||||
|
- 'alias /var/tmp;'
|
||||||
location:
|
location:
|
||||||
'/':
|
'/':
|
||||||
- 'alias /var/tmp;'
|
- 'alias /var/tmp;'
|
||||||
'/a':
|
'/a':
|
||||||
- 'alias /var/tmp;'
|
- 'alias /var/tmp;'
|
||||||
'/b':
|
location_order_before:
|
||||||
- 'alias /var/tmp;'
|
- '/b'
|
||||||
'/c':
|
- '/c'
|
||||||
- 'alias /var/tmp;'
|
|
||||||
location_order:
|
location_order:
|
||||||
- '/'
|
- '/'
|
||||||
- '/a'
|
- '/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 }}"
|
php_upstream: "manual"
|
||||||
upstream_params:
|
upstream_params:
|
||||||
- 'fastcgi_param FOO bar;'
|
- 'fastcgi_param FOO bar;'
|
||||||
redirect_from:
|
redirect_from:
|
||||||
@@ -201,8 +226,10 @@
|
|||||||
use_access_log: true
|
use_access_log: true
|
||||||
- name: 'test-php-index.local'
|
- name: 'test-php-index.local'
|
||||||
template: '_php_index'
|
template: '_php_index'
|
||||||
|
php_upstream: 'hx_unix'
|
||||||
- name: 'test-php-index2.local'
|
- name: 'test-php-index2.local'
|
||||||
template: '_php_index2'
|
template: '_php_index2'
|
||||||
|
php_upstream: 'hx_ip'
|
||||||
- name: 'test-proxy.local'
|
- name: 'test-proxy.local'
|
||||||
listen:
|
listen:
|
||||||
- 8080
|
- 8080
|
||||||
@@ -214,15 +241,15 @@
|
|||||||
state: 'absent'
|
state: 'absent'
|
||||||
- name: 'redirect-to.local'
|
- name: 'redirect-to.local'
|
||||||
redirect_to: 'http://test.local'
|
redirect_to: 'http://test.local'
|
||||||
- name: 'backuppc.local'
|
|
||||||
template: '_backuppc'
|
|
||||||
htpasswd: 'hello'
|
|
||||||
- name: 'nagios3.local'
|
|
||||||
template: '_nagios3'
|
|
||||||
htpasswd: 'nagios'
|
|
||||||
- name: 'test-ssl.local'
|
- name: 'test-ssl.local'
|
||||||
proto: ['http', 'https']
|
proto: ['http', 'https']
|
||||||
template: '_base'
|
template: '_base'
|
||||||
|
- name:
|
||||||
|
- 'test-ssl-selfsigned.local'
|
||||||
|
- 'www.test-ssl-selfsigned.local'
|
||||||
|
proto: ['http', 'https']
|
||||||
|
template: '_base'
|
||||||
|
hsts: 'max-age=1664;'
|
||||||
- name: 'test-ssl-predeployed.local'
|
- name: 'test-ssl-predeployed.local'
|
||||||
proto: ['http', 'https']
|
proto: ['http', 'https']
|
||||||
template: '_base'
|
template: '_base'
|
||||||
@@ -248,288 +275,299 @@
|
|||||||
- 'www.test-ssl-redirect-many2.local'
|
- 'www.test-ssl-redirect-many2.local'
|
||||||
- name: 'test-ssl-proxy-protocol.local'
|
- name: 'test-ssl-proxy-protocol.local'
|
||||||
proto: ['http', 'https']
|
proto: ['http', 'https']
|
||||||
listen: [80, 20080]
|
listen_proxy_protocol: [20080]
|
||||||
listen_ssl: [443, 20443]
|
listen_proxy_protocol_ssl: [20443]
|
||||||
http_proxy_protocol_port: [20080]
|
|
||||||
https_proxy_protocol_port: [20443]
|
|
||||||
template: '_base'
|
template: '_base'
|
||||||
ssl_name: 'test-ssl.local'
|
ssl_name: 'test-ssl.local'
|
||||||
|
headers:
|
||||||
|
'X-Proxy-Protocol': '1'
|
||||||
- name: '{{ ngrok.stdout }}'
|
- name: '{{ ngrok.stdout }}'
|
||||||
proto: ['http', 'https']
|
proto: ['http', 'https']
|
||||||
|
listen_proxy_protocol: [21080]
|
||||||
|
listen_proxy_protocol_ssl: [21443]
|
||||||
template: '_base'
|
template: '_base'
|
||||||
ssl_name: '{{ ngrok.stdout }}'
|
ssl_name: '{{ ngrok.stdout }}'
|
||||||
headers:
|
headers:
|
||||||
'X-acme': '1'
|
'X-acme': '1'
|
||||||
|
- name: 'test-custom-template.local'
|
||||||
|
custom_template: 'templates/custom_template.conf.j2'
|
||||||
|
root: '/tmp/custom-template'
|
||||||
|
|
||||||
|
nginx_php: "{{ [{'upstream_name': 'manual', 'sockets': [{'host': '127.0.0.1', 'port': '9636' }] }] }}"
|
||||||
nginx_dh_length: 1024
|
nginx_dh_length: 1024
|
||||||
roles:
|
roles:
|
||||||
- ../../
|
- ../../
|
||||||
post_tasks:
|
post_tasks:
|
||||||
# --------------------------------
|
# --------------------------------
|
||||||
# Apps
|
# Apps
|
||||||
# --------------------------------
|
# --------------------------------
|
||||||
- name: INCLUDE | Post_tasks related to OS version
|
- name: INCLUDE_TASKS | Post_tasks related to OS version
|
||||||
include: "includes/post_{{ ansible_distribution }}.yml"
|
ansible.builtin.include_tasks: "includes/post_{{ ansible_distribution }}.yml"
|
||||||
|
|
||||||
# --------------------------------
|
# --------------------------------
|
||||||
# Deploy index files
|
# Deploy index files
|
||||||
# --------------------------------
|
# --------------------------------
|
||||||
- name: -- Add PHP file --
|
- name: -- Add PHP file --
|
||||||
copy:
|
ansible.builtin.copy:
|
||||||
dest: "{{ nginx_root }}/{{ item }}/public/index.php"
|
dest: "{{ nginx_root }}/{{ item }}/public/index.php"
|
||||||
content: "<?php phpinfo();"
|
content: "<?php phpinfo();"
|
||||||
with_items:
|
mode: 0644
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
loop:
|
||||||
- 'test-php.local'
|
- 'test-php.local'
|
||||||
- 'test-php-index.local'
|
- 'test-php-index.local'
|
||||||
- 'test-php-index2.local'
|
- 'test-php-index2.local'
|
||||||
|
|
||||||
|
- name: -- Add Directories --
|
||||||
|
file:
|
||||||
|
path: "{{ item }}"
|
||||||
|
state: directory
|
||||||
|
loop:
|
||||||
|
- "{{ nginx_root }}/test-htpasswd.local/public/hello"
|
||||||
|
- "/tmp/custom-template"
|
||||||
|
|
||||||
- name: -- Add HTML file --
|
- name: -- Add HTML file --
|
||||||
copy:
|
ansible.builtin.copy:
|
||||||
dest: "{{ item }}/index.html"
|
dest: "{{ item }}/index.html"
|
||||||
content: "Index HTML test OK\n"
|
content: "Index HTML test OK\n"
|
||||||
with_items:
|
mode: 0644
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
loop:
|
||||||
- '{{ nginx_root }}/first-test/public'
|
- '{{ nginx_root }}/first-test/public'
|
||||||
- '/var/tmp'
|
- '/var/tmp'
|
||||||
- '{{ nginx_root }}/test-htpasswd-all.local/public'
|
- '{{ nginx_root }}/test-htpasswd-all.local/public'
|
||||||
- '{{ nginx_root }}/test-ssl.local/public'
|
- '{{ nginx_root }}/test-ssl.local/public'
|
||||||
|
- '{{ nginx_root }}/test-ssl-selfsigned.local/public'
|
||||||
- '{{ nginx_root }}/test-ssl-predeployed.local/public'
|
- '{{ nginx_root }}/test-ssl-predeployed.local/public'
|
||||||
- '{{ nginx_root }}/test-ssl-proxy-protocol.local/public'
|
- '{{ nginx_root }}/test-ssl-proxy-protocol.local/public'
|
||||||
- '{{ nginx_root }}/{{ ngrok.stdout }}/public'
|
- '{{ nginx_root }}/{{ ngrok.stdout }}/public'
|
||||||
|
|
||||||
- name: -- Create directory --
|
- name: -- Create directory --
|
||||||
file:
|
ansible.builtin.file:
|
||||||
path: "{{ nginx_root }}/test-htpasswd.local/public/hello"
|
path: "{{ nginx_root }}/test-htpasswd.local/public/hello"
|
||||||
state: directory
|
state: directory
|
||||||
|
mode: 0755
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
|
||||||
- name: -- Add HTML file hello --
|
- name: -- Add HTML file hello --
|
||||||
copy:
|
ansible.builtin.copy:
|
||||||
dest: "{{ nginx_root }}/test-htpasswd.local/public/hello/index.html"
|
dest: "{{ nginx_root }}/test-htpasswd.local/public/hello/index.html"
|
||||||
content: "hello\n"
|
content: "hello\n"
|
||||||
|
mode: 0644
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
|
||||||
# --------------------------------
|
# --------------------------------
|
||||||
# Test custom facts
|
# Test custom facts
|
||||||
# --------------------------------
|
# --------------------------------
|
||||||
- name: -- CHECK FACTS --
|
- name: -- CHECK FACTS --
|
||||||
assert:
|
ansible.builtin.assert:
|
||||||
that: "'{{ ansible_local.nginx.fact_nginx_sites[0].name[0] }}' == 'test.local'"
|
that: "'{{ ansible_local.nginx.fact_nginx_sites[0].name[0] }}' == 'test.local'"
|
||||||
# --------------------------------
|
|
||||||
# Simple sites tests
|
# --------------------------------
|
||||||
# --------------------------------
|
# Simple sites tests
|
||||||
|
# --------------------------------
|
||||||
- name: -- VERIFY SITES --
|
- name: -- VERIFY SITES --
|
||||||
uri:
|
ansible.builtin.uri:
|
||||||
url: "http://{{ item | nginx_site_name }}{% if item.listen is defined %}:{{ item.listen[0] }}{% endif %}/"
|
url: "http://{{ item | nginx_site_name }}{% if item.listen is defined %}:{{ item.listen[0] }}{% endif %}/"
|
||||||
status_code: '200,301,302,401,403'
|
status_code: '200,301,302,401,403'
|
||||||
follow_redirects: none
|
follow_redirects: none
|
||||||
with_items: "{{ nginx_sites }}"
|
loop: "{{ nginx_sites }}"
|
||||||
when: item.state is undefined or item.state != "absent"
|
when: item.state is undefined or item.state != "absent"
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
|
||||||
- name: -- VERIFY FORBIDDEN --
|
- name: -- VERIFY FORBIDDEN --
|
||||||
uri:
|
ansible.builtin.uri:
|
||||||
url: "http://test-php-index.local/phpinfo.php"
|
url: "http://test-php-index.local/phpinfo.php"
|
||||||
status_code: 403
|
status_code: 403
|
||||||
|
|
||||||
- name: -- VERIFY REDIRECT SITES --
|
- name: -- VERIFY REDIRECT SITES --
|
||||||
uri:
|
ansible.builtin.uri:
|
||||||
url: "http://{{ item.redirect_from[0] }}/"
|
url: "http://{{ item.redirect_from[0] }}/"
|
||||||
status_code: 301
|
status_code: 301
|
||||||
follow_redirects: none
|
follow_redirects: none
|
||||||
with_items: "{{ nginx_sites }}"
|
loop: "{{ 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)
|
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 HTTPS SITES --
|
- name: -- VERIFY REDIRECT HTTPS SITES --
|
||||||
uri:
|
ansible.builtin.uri:
|
||||||
url: "https://{{ item.redirect_from[0] }}:{{ item.listen_ssl[0] | default(443) }}/"
|
url: "https://{{ item.redirect_from[0] }}:{{ item.listen_ssl[0] | default(443) }}/"
|
||||||
status_code: 301
|
status_code: 301
|
||||||
follow_redirects: none
|
follow_redirects: none
|
||||||
validate_certs: no
|
validate_certs: false
|
||||||
with_items: "{{ nginx_sites }}"
|
loop: "{{ 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
|
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
|
||||||
|
|
||||||
# --------------------------------
|
# --------------------------------
|
||||||
# PHP
|
# PHP
|
||||||
# --------------------------------
|
# --------------------------------
|
||||||
- name: -- VERIFY PHP SITES --
|
- name: -- VERIFY PHP SITES --
|
||||||
uri:
|
ansible.builtin.uri:
|
||||||
url: "http://{{ item.name}}/"
|
url: "http://{{ item.name }}/"
|
||||||
return_content: yes
|
return_content: true
|
||||||
register: p
|
register: p
|
||||||
with_items: "{{ nginx_sites }}"
|
loop: "{{ nginx_sites }}"
|
||||||
when: >
|
when: >
|
||||||
item.template is defined and
|
item.template is defined and
|
||||||
(item.template == '_php' or item.template == '_php_index' or item.template == '_php_index2')
|
(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
|
failed_when: p.content.find('PHP Version') == -1
|
||||||
|
|
||||||
- name: -- VERIFY INDEX2 --
|
- name: -- VERIFY INDEX2 --
|
||||||
uri:
|
ansible.builtin.uri:
|
||||||
url: "http://test-php-index2.local/lorem.php?ipsum=sit&dolor=amet"
|
url: "http://test-php-index2.local/lorem.php?ipsum=sit&dolor=amet"
|
||||||
return_content: yes
|
return_content: true
|
||||||
register: p2
|
register: p2
|
||||||
failed_when: p2.content.find('PHP Version') == -1
|
failed_when: p2.content.find('PHP Version') == -1
|
||||||
|
|
||||||
# --------------------------------
|
# --------------------------------
|
||||||
# Basic Auth
|
# Basic Auth
|
||||||
# --------------------------------
|
# --------------------------------
|
||||||
- name: -- VERIFY AUTH BASIC NONE --
|
- name: -- VERIFY AUTH BASIC NONE --
|
||||||
uri:
|
ansible.builtin.uri:
|
||||||
url: "http://test-htpasswd.local/hello/"
|
url: "http://test-htpasswd.local/hello/"
|
||||||
status_code: 401
|
status_code: 401
|
||||||
|
|
||||||
- name: -- VERIFY AUTH BASIC FAIL --
|
- name: -- VERIFY AUTH BASIC FAIL --
|
||||||
uri:
|
ansible.builtin.uri:
|
||||||
url: "http://test-htpasswd.local/hello/"
|
url: "http://test-htpasswd.local/hello/"
|
||||||
status_code: 401
|
status_code: 401
|
||||||
user: "fail"
|
user: "fail"
|
||||||
password: "fail"
|
password: "fail"
|
||||||
force_basic_auth: yes
|
force_basic_auth: true
|
||||||
|
|
||||||
- name: -- VERIFY AUTH BASIC OK --
|
- name: -- VERIFY AUTH BASIC OK --
|
||||||
uri:
|
ansible.builtin.uri:
|
||||||
url: "http://test-htpasswd.local/hello/"
|
url: "http://test-htpasswd.local/hello/"
|
||||||
user: "hanx"
|
user: "hanx"
|
||||||
password: "qwerty"
|
password: "qwerty"
|
||||||
force_basic_auth: yes
|
force_basic_auth: true
|
||||||
|
|
||||||
- name: -- VERIFY AUTH BASIC FAIL GLOBAL --
|
- name: -- VERIFY AUTH BASIC FAIL GLOBAL --
|
||||||
uri:
|
ansible.builtin.uri:
|
||||||
url: "http://test-htpasswd-all.local/"
|
url: "http://test-htpasswd-all.local/"
|
||||||
status_code: 401
|
status_code: 401
|
||||||
user: "fail"
|
user: "fail"
|
||||||
password: "fail"
|
password: "fail"
|
||||||
force_basic_auth: yes
|
force_basic_auth: true
|
||||||
|
|
||||||
- name: -- VERIFY AUTH BASIC OK GLOBAL --
|
- name: -- VERIFY AUTH BASIC OK GLOBAL --
|
||||||
uri:
|
ansible.builtin.uri:
|
||||||
url: "http://test-htpasswd-all.local/"
|
url: "http://test-htpasswd-all.local/"
|
||||||
user: "hanx"
|
user: "hanx"
|
||||||
password: "qwerty"
|
password: "qwerty"
|
||||||
force_basic_auth: yes
|
force_basic_auth: true
|
||||||
|
|
||||||
# --------------------------------
|
# --------------------------------
|
||||||
# BackupPC
|
# SSL
|
||||||
# --------------------------------
|
# --------------------------------
|
||||||
- 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 --
|
- name: -- VERIFY SSL --
|
||||||
uri:
|
ansible.builtin.uri:
|
||||||
url: "https://{{ item }}/"
|
url: "https://{{ item }}/"
|
||||||
return_content: yes
|
return_content: true
|
||||||
validate_certs: no
|
validate_certs: false
|
||||||
register: sslok
|
register: sslok
|
||||||
failed_when: sslok.content.find('Index HTML test OK') == -1
|
failed_when: sslok.content.find('Index HTML test OK') == -1
|
||||||
with_items:
|
loop:
|
||||||
- 'test-ssl-predeployed.local'
|
- 'test-ssl-predeployed.local'
|
||||||
|
- 'test-ssl-selfsigned.local'
|
||||||
- 'test-ssl.local'
|
- 'test-ssl.local'
|
||||||
- '{{ ngrok.stdout }}'
|
- '{{ ngrok.stdout }}'
|
||||||
|
|
||||||
- name: -- VERIFY SSL REDIRECT --
|
- name: -- VERIFY SSL REDIRECT --
|
||||||
uri:
|
ansible.builtin.uri:
|
||||||
url: "http://{{ item.name }}/"
|
url: "http://{{ item.name }}/"
|
||||||
validate_certs: no
|
validate_certs: false
|
||||||
status_code: 301
|
status_code: 301
|
||||||
return_content: yes
|
return_content: true
|
||||||
follow_redirects: none
|
follow_redirects: none
|
||||||
register: sslredirok
|
register: sslredirok
|
||||||
failed_when: '"https://%s%s" % (item.name, ":" + item.port if item.port is defined else "") not in sslredirok.location'
|
failed_when: '"https://%s%s" % (item.name, ":" + item.port if item.port is defined else "") not in sslredirok.location'
|
||||||
with_items:
|
loop:
|
||||||
- name: 'test-ssl-redirect.local'
|
- name: 'test-ssl-redirect.local'
|
||||||
- name: 'test-ssl-redirect-many.local'
|
- name: 'test-ssl-redirect-many.local'
|
||||||
port: '8443'
|
port: '8443'
|
||||||
- name: 'test-ssl-redirect-many2.local'
|
- name: 'test-ssl-redirect-many2.local'
|
||||||
port: '8443'
|
port: '8443'
|
||||||
|
|
||||||
# --------------------------------
|
# --------------------------------
|
||||||
# Default sites
|
# Default sites
|
||||||
# --------------------------------
|
# --------------------------------
|
||||||
- name: -- VERIFY DEFAULT SITE --
|
- name: -- VERIFY DEFAULT SITE --
|
||||||
uri:
|
ansible.builtin.uri:
|
||||||
url: 'http://127.0.0.1/'
|
url: 'http://127.0.0.1/'
|
||||||
return_content: yes
|
return_content: true
|
||||||
register: vdefault
|
register: vdefault
|
||||||
failed_when: >
|
failed_when: >
|
||||||
vdefault.content.find('Index HTML test OK') == -1 or
|
vdefault.content.find('Index HTML test OK') == -1 or
|
||||||
vdefault.x_ansible_default is not defined
|
vdefault.x_ansible_default is not defined
|
||||||
|
|
||||||
- name: -- VERIFY DEFAULT SITE + STUB STATUS--
|
- name: -- VERIFY DEFAULT SITE + STUB STATUS--
|
||||||
uri:
|
ansible.builtin.uri:
|
||||||
url: 'http://127.0.0.1/status'
|
url: 'http://127.0.0.1/status'
|
||||||
return_content: yes
|
return_content: true
|
||||||
register: vdefault_status
|
register: vdefault_status
|
||||||
failed_when: >
|
failed_when: >
|
||||||
vdefault_status.content.find('Active connections') == -1 or
|
vdefault_status.content.find('Active connections') == -1 or
|
||||||
vdefault_status.x_ansible_default is not defined
|
vdefault_status.x_ansible_default is not defined
|
||||||
|
|
||||||
- name: -- VERIFY DEFAULT SSL SITE --
|
- name: -- VERIFY DEFAULT SSL SITE --
|
||||||
uri:
|
ansible.builtin.uri:
|
||||||
url: 'https://127.0.0.1/'
|
url: 'https://127.0.0.1/'
|
||||||
return_content: yes
|
return_content: true
|
||||||
validate_certs: no
|
validate_certs: false
|
||||||
register: vdefault
|
register: vdefault
|
||||||
failed_when: >
|
failed_when: >
|
||||||
vdefault.content.find('Index HTML test OK') == -1 or
|
vdefault.content.find('Index HTML test OK') == -1 or
|
||||||
vdefault.x_ansible_default is not defined
|
vdefault.x_ansible_default is not defined
|
||||||
|
|
||||||
- name: -- VERIFY NOT DEFAULT SITE --
|
- name: -- VERIFY NOT DEFAULT SITE --
|
||||||
uri:
|
ansible.builtin.uri:
|
||||||
url: 'http://test-php.local/'
|
url: 'http://test-php.local/'
|
||||||
return_content: yes
|
return_content: true
|
||||||
register: vphp
|
register: vphp
|
||||||
failed_when: vphp.x_ansible_default is defined
|
failed_when: vphp.x_ansible_default is defined
|
||||||
|
|
||||||
- name: -- VERIFY NOT DEFAULT SSL SITE --
|
- name: -- VERIFY NOT DEFAULT SSL SITE --
|
||||||
uri:
|
ansible.builtin.uri:
|
||||||
url: 'https://test-ssl.local/'
|
url: 'https://test-ssl.local/'
|
||||||
return_content: yes
|
return_content: true
|
||||||
validate_certs: no
|
validate_certs: false
|
||||||
register: notdefaultssl
|
register: notdefaultssl
|
||||||
failed_when: notdefaultssl.x_ansible_default is defined
|
failed_when: notdefaultssl.x_ansible_default is defined
|
||||||
|
|
||||||
# --------------------------------
|
# --------------------------------
|
||||||
# Check HTTP2
|
# Check Proxy protocol
|
||||||
# --------------------------------
|
# Note: Debian Stretch doesn't any version of curl with "--haproxy-protocol" argument
|
||||||
- name: SHELL | Check HTTP2
|
# --------------------------------
|
||||||
shell: nghttp -nv https://localhost 2> /dev/null | grep -q h2
|
- block:
|
||||||
|
|
||||||
|
- name: SHELL | Check HTTP proxy protocol
|
||||||
|
ansible.builtin.shell: set -o pipefail && curl -I --haproxy-protocol http://test-ssl-proxy-protocol.local:20080 | grep -qi 'X-Proxy-Protocol'
|
||||||
args:
|
args:
|
||||||
executable: /bin/sh
|
executable: /bin/bash
|
||||||
|
warn: false
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
|
- name: SHELL | Check HTTPS proxy protocol
|
||||||
|
ansible.builtin.shell: set -o pipefail && curl -I --haproxy-protocol -k https://test-ssl-proxy-protocol.local:20443 | grep -qi 'X-Proxy-Protocol'
|
||||||
|
args:
|
||||||
|
executable: /bin/bash
|
||||||
|
warn: false
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
|
when: not (ansible_distribution == 'Debian' and ansible_distribution_major_version is version('9', 'eq'))
|
||||||
|
|
||||||
|
# --------------------------------
|
||||||
|
# Check HTTP2
|
||||||
|
# --------------------------------
|
||||||
|
- name: SHELL | Check HTTP2
|
||||||
|
ansible.builtin.shell: set -o pipefail && nghttp -nv https://localhost 2> /dev/null | grep -q h2
|
||||||
|
args:
|
||||||
|
executable: /bin/bash
|
||||||
changed_when: false
|
changed_when: false
|
||||||
when: nginx_auto_config_httpv2 and 'http_v2' in nginx_modules
|
when: nginx_auto_config_httpv2 and 'http_v2' in nginx_modules
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
|
---
|
||||||
|
|
||||||
nginx_events_use: 'epoll'
|
nginx_events_use: 'epoll'
|
||||||
nginx_pid: '/run/nginx.pid'
|
nginx_pid: '/run/nginx.pid'
|
||||||
nginx_etc_dir: '/etc/nginx'
|
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'
|
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
|
---
|
||||||
|
|
||||||
nginx_events_use: 'kqueue'
|
nginx_events_use: 'kqueue'
|
||||||
nginx_pid: '/var/run/nginx.pid'
|
nginx_pid: '/var/run/nginx.pid'
|
||||||
nginx_etc_dir: '/usr/local/etc/nginx'
|
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'
|
nginx_acmesh_bin: '/usr/local/sbin/acme.sh'
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
---
|
||||||
|
|
||||||
nginx_upstream_server_params:
|
nginx_upstream_server_params:
|
||||||
- key: 'weight'
|
- key: 'weight'
|
||||||
default: 1
|
default: 1
|
||||||
@@ -40,13 +42,11 @@ nginx_dirs:
|
|||||||
owner: "root"
|
owner: "root"
|
||||||
|
|
||||||
nginx_templates_no_dir:
|
nginx_templates_no_dir:
|
||||||
- '_backuppc'
|
|
||||||
- '_nagios3'
|
|
||||||
- '_proxy'
|
- '_proxy'
|
||||||
|
|
||||||
nginx_servers_default_headers:
|
nginx_servers_default_headers:
|
||||||
'X-Frame-Options': 'DENY always'
|
'X-Frame-Options': 'DENY always'
|
||||||
'X-Content-Type-Options': 'nosniff always'
|
'X-Content-Type-Options': 'nosniff always'
|
||||||
'X-XSS-Protection': '1; mode=block'
|
'X-XSS-Protection': '1; mode=block always'
|
||||||
|
|
||||||
nginx_acmesh_bin: "{{ nginx_acmesh_dir }}/acme.sh"
|
nginx_acmesh_bin: "{{ nginx_acmesh_dir }}/acme.sh"
|
||||||
|
|||||||
Reference in New Issue
Block a user