mirror of
https://github.com/HanXHX/ansible-nginx.git
synced 2026-02-28 09:22:10 +07:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5b0977567c | ||
|
|
de71e1bdcc | ||
|
|
19cdab5ba4 | ||
|
|
999f226838 | ||
|
|
40f67fc103 | ||
|
|
6b1366298f | ||
|
|
817d56fb81 | ||
|
|
e08401acf8 | ||
|
|
0bda544a2f | ||
|
|
2641777abe | ||
|
|
60a368f3e1 | ||
|
|
41a5575627 | ||
|
|
42bb4a3e2b | ||
|
|
ef3440a015 |
11
.travis.yml
11
.travis.yml
@@ -1,15 +1,20 @@
|
|||||||
env:
|
matrix:
|
||||||
- PLATFORM=debian-jessie
|
include:
|
||||||
|
- env: PLATFORM=debian-jessie ORIGIN=debian NGINX_PHP56=true NGINX_PHP70=false NGINX_BACKPORTS=false DOTDEB=false
|
||||||
|
- env: PLATFORM=debian-jessie ORIGIN=backports NGINX_PHP56=true NGINX_PHP70=false NGINX_BACKPORTS=true DOTDEB=false
|
||||||
|
- env: PLATFORM=debian-jessie ORIGIN=dotdeb NGINX_PHP56=true NGINX_PHP70=true NGINX_BACKPORTS=false DOTDEB=true
|
||||||
|
|
||||||
sudo: required
|
sudo: required
|
||||||
|
|
||||||
|
dist: trusty
|
||||||
|
|
||||||
language: python
|
language: python
|
||||||
|
|
||||||
services:
|
services:
|
||||||
- docker
|
- docker
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- docker build -f tests/$PLATFORM.Dockerfile -t test-$PLATFORM . && docker run --name $PLATFORM test-$PLATFORM
|
- docker build -f tests/$PLATFORM.Dockerfile -t test-$PLATFORM . && docker run -e "DOTDEB=$DOTDEB" -e "NGINX_PHP56=$NGINX_PHP56" -e "NGINX_PHP70=$NGINX_PHP70" -e "NGINX_BACKPORTS=$NGINX_BACKPORTS" --name $PLATFORM test-$PLATFORM
|
||||||
|
|
||||||
notifications:
|
notifications:
|
||||||
webhooks: https://galaxy.ansible.com/api/v1/notifications/
|
webhooks: https://galaxy.ansible.com/api/v1/notifications/
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ Features:
|
|||||||
- Fast PHP configuration
|
- Fast PHP configuration
|
||||||
- Preconfigured vhost templates (should work on many app)
|
- Preconfigured vhost templates (should work on many app)
|
||||||
- Auto-configure HTTP2 on SSL/TLS vhosts
|
- Auto-configure HTTP2 on SSL/TLS vhosts
|
||||||
|
- Manage dynamic modules (install and loading)
|
||||||
|
|
||||||
Requirements
|
Requirements
|
||||||
------------
|
------------
|
||||||
@@ -50,6 +51,7 @@ FreeBSD:
|
|||||||
- `nginx_events_*`: all variables in events block
|
- `nginx_events_*`: all variables in events block
|
||||||
- `nginx_http_*`: all variables in http block
|
- `nginx_http_*`: all variables in http block
|
||||||
- `nginx_custom_http`: instructions list (will put data in `/etc/nginx/conf.d/custom.conf`)
|
- `nginx_custom_http`: instructions list (will put data in `/etc/nginx/conf.d/custom.conf`)
|
||||||
|
- `nginx_dyn_modules`: dynamic module list to load
|
||||||
|
|
||||||
Fine configuration
|
Fine configuration
|
||||||
------------------
|
------------------
|
||||||
|
|||||||
23
Vagrantfile
vendored
23
Vagrantfile
vendored
@@ -6,12 +6,14 @@
|
|||||||
Vagrant.configure("2") do |config|
|
Vagrant.configure("2") do |config|
|
||||||
|
|
||||||
vms_debian = [
|
vms_debian = [
|
||||||
[ "debian-jessie", "debian/jessie64" ],
|
{ :name => "debian-jessie", :box => "debian/jessie64", :vars => { "nginx_php56": true, "nginx_php70": false, "dotdeb": false, "nginx_backports": false }},
|
||||||
[ "debian-stretch", "sharlak/debian_stretch_64" ]
|
{ :name => "debian-jessie-backports", :box => "debian/jessie64", :vars => { "nginx_php56": true, "nginx_php70": false, "dotdeb": false, "nginx_backports": true }},
|
||||||
|
{ :name => "debian-jessie-dotdeb", :box => "debian/jessie64", :vars => { "nginx_php56": true, "nginx_php70": true, "dotdeb": true, "nginx_backports": false }},
|
||||||
|
{ :name => "debian-stretch", :box => "sharlak/debian_stretch_64", :vars => { "nginx_php56": false, "nginx_php70": true, "dotdeb": false, "nginx_backports": false }}
|
||||||
]
|
]
|
||||||
|
|
||||||
vms_freebsd = [
|
vms_freebsd = [
|
||||||
[ "freebsd-10.2", "freebsd/FreeBSD-10.2-STABLE" ]
|
{ :name => "freebsd-10.2", :box => "freebsd/FreeBSD-10.2-STABLE" }
|
||||||
]
|
]
|
||||||
|
|
||||||
config.vm.provider "virtualbox" do |v|
|
config.vm.provider "virtualbox" do |v|
|
||||||
@@ -19,22 +21,22 @@ Vagrant.configure("2") do |config|
|
|||||||
v.memory = 256
|
v.memory = 256
|
||||||
end
|
end
|
||||||
|
|
||||||
vms_debian.each do |vm|
|
vms_debian.each do |opts|
|
||||||
config.vm.define vm[0] do |m|
|
config.vm.define opts[:name] do |m|
|
||||||
m.vm.box = vm[1]
|
m.vm.box = opts[:box]
|
||||||
m.vm.network "private_network", type: "dhcp"
|
m.vm.network "private_network", type: "dhcp"
|
||||||
m.vm.provision "ansible" do |ansible|
|
m.vm.provision "ansible" do |ansible|
|
||||||
ansible.playbook = "tests/test.yml"
|
ansible.playbook = "tests/test.yml"
|
||||||
ansible.groups = { "test" => [ vm[0] ] }
|
|
||||||
ansible.verbose = 'vv'
|
ansible.verbose = 'vv'
|
||||||
ansible.sudo = true
|
ansible.sudo = true
|
||||||
|
ansible.extra_vars = opts[:vars]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
# See: https://forums.freebsd.org/threads/52717/
|
# See: https://forums.freebsd.org/threads/52717/
|
||||||
vms_freebsd.each do |vm|
|
vms_freebsd.each do |opts|
|
||||||
config.vm.define vm[0] do |m|
|
config.vm.define opts[:name] do |m|
|
||||||
m.vm.box = vm[1]
|
m.vm.box = opts[:box]
|
||||||
m.vm.network "private_network", type: "dhcp"
|
m.vm.network "private_network", type: "dhcp"
|
||||||
m.vm.guest = :freebsd
|
m.vm.guest = :freebsd
|
||||||
m.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: true
|
m.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: true
|
||||||
@@ -43,7 +45,6 @@ Vagrant.configure("2") do |config|
|
|||||||
m.vm.provision "shell", inline: "pkg install -y python bash"
|
m.vm.provision "shell", inline: "pkg install -y python bash"
|
||||||
m.vm.provision "ansible" do |ansible|
|
m.vm.provision "ansible" do |ansible|
|
||||||
ansible.playbook = "tests/test.yml"
|
ansible.playbook = "tests/test.yml"
|
||||||
ansible.groups = { "test" => [ vm[0] ] }
|
|
||||||
ansible.verbose = 'vv'
|
ansible.verbose = 'vv'
|
||||||
ansible.sudo = true
|
ansible.sudo = true
|
||||||
ansible.extra_vars = {
|
ansible.extra_vars = {
|
||||||
|
|||||||
@@ -105,6 +105,11 @@ nginx_htpasswd: []
|
|||||||
#
|
#
|
||||||
nginx_ssl_pairs: []
|
nginx_ssl_pairs: []
|
||||||
|
|
||||||
|
#
|
||||||
|
# Dynamic modules
|
||||||
|
#
|
||||||
|
nginx_dyn_modules: []
|
||||||
|
|
||||||
#
|
#
|
||||||
# Diffie-Hellman
|
# Diffie-Hellman
|
||||||
#
|
#
|
||||||
|
|||||||
16
doc/ssl.md
16
doc/ssl.md
@@ -32,7 +32,8 @@ Note: `name` is used to deploy key/cert. With defaults values dans `name` = "foo
|
|||||||
Tips
|
Tips
|
||||||
----
|
----
|
||||||
|
|
||||||
Deploying key/cert is not mandatory with this role. You can manage it in other place ([letsencrypt](https://letsencrypt.org/)? :)). You just need to set `dest_cert` and `dest_key`!
|
- Deploying key/cert is not mandatory with this role. You can manage it in other place ([letsencrypt](https://letsencrypt.org/)? :)). You just need to set `dest_cert` and `dest_key`!
|
||||||
|
- In `nginx_vhosts`, `ssl_name` is mandatory. This role will search in `nginx_ssl_pairs` with vhost `name` (first in list if it's a list).
|
||||||
|
|
||||||
Diffie-Hellman
|
Diffie-Hellman
|
||||||
--------------
|
--------------
|
||||||
@@ -48,6 +49,9 @@ nginx_vhosts;
|
|||||||
proto: ['http', 'https']
|
proto: ['http', 'https']
|
||||||
template: '_base'
|
template: '_base'
|
||||||
ssl_name: 'mysuperkey'
|
ssl_name: 'mysuperkey'
|
||||||
|
- name: 'test-ssl2.local'
|
||||||
|
proto: ['http', 'https']
|
||||||
|
template: '_base'
|
||||||
|
|
||||||
nginx_ssl_pairs:
|
nginx_ssl_pairs:
|
||||||
- name: mysuperkey
|
- name: mysuperkey
|
||||||
@@ -59,5 +63,15 @@ nginx_ssl_pairs:
|
|||||||
-----BEGIN CERTIFICATE-----
|
-----BEGIN CERTIFICATE-----
|
||||||
....(snip)....
|
....(snip)....
|
||||||
-----END CERTIFICATE-----
|
-----END CERTIFICATE-----
|
||||||
|
- name: test-ssl2.local
|
||||||
|
key: |
|
||||||
|
-----BEGIN RSA PRIVATE KEY-----
|
||||||
|
....(snip)....
|
||||||
|
-----END RSA PRIVATE KEY-----
|
||||||
|
cert: |
|
||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
....(snip)....
|
||||||
|
-----END CERTIFICATE-----
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -18,14 +18,15 @@ Common
|
|||||||
- `redirect_to_code`: Redirect code (default: 302)
|
- `redirect_to_code`: Redirect code (default: 302)
|
||||||
- `redirect_https`: (O) Boolean. Redirect HTTP to HTTPS. If "true", you _MUST_ set `proto` to ```['https']```.
|
- `redirect_https`: (O) Boolean. Redirect HTTP to HTTPS. If "true", you _MUST_ set `proto` to ```['https']```.
|
||||||
- `location`: (O) Add new custom locations (it does not overwrite!)
|
- `location`: (O) Add new custom locations (it does not overwrite!)
|
||||||
|
- `location_order`: (O) Due to non preditive `location` order, you can provide the good order (see test-location.local in [tests/test.yml](../tests/test.yml)).
|
||||||
- `more`: (O) Add more custom infos.
|
- `more`: (O) Add more custom infos.
|
||||||
- `upstream_params`: (O) Add upstream params (useful when you want to pass variables to PHP)
|
- `upstream_params`: (O) Add upstream params (useful when you want to pass variables to PHP)
|
||||||
- `override_try_files`: (O) overrides default try\_files defined in template
|
- `override_try_files`: (O) overrides default try\_files defined in template
|
||||||
- `manage_local_content`: (O) Boolean. Set to false if you do not want to manage local content (images, css...). This option is useless if you use `_proxy` template or `redirect_to` feature.
|
- `manage_local_content`: (O) Boolean. Set to false if you do not want to manage local content (images, css...). This option is useless if you use `_proxy` template or `redirect_to` feature.
|
||||||
- `htpasswd`: (O) References name key in `nginx_htpasswd`. Enable auth basic on all vhost.
|
- `htpasswd`: (O) References name key in `nginx_htpasswd`. Enable auth basic on all vhost.
|
||||||
- `proto`: (O) list of protocol used. Default is a list with "http". If you need http and https, you must set a list with "http" and "https". You can only set "https" without http support.
|
- `proto`: (O) list of protocol used. Default is a list with "http". If you need http and https, you must set a list with "http" and "https". You can only set "https" without http support.
|
||||||
- `ssl_name`: (D) name of the key used when using TLS/SSL. Mandatory when `proto` contains "https"
|
- `ssl_name`: (D) name of the key used when using TLS/SSL. Optional when `proto` contains "https". If you don't set this value, it will search by `name`.
|
||||||
- `ssl_template` (O) "strong" (default) or "legacy". You can disable SSL helpers and add your own directives by setting "false".
|
- `ssl_template` (O) "strong" (default) or "legacy". You can disable SSL helpers and add your own directives by setting "false".
|
||||||
- `php_version` (O) Sepecify PHP version (5 or 7)
|
- `php_version` (O) Sepecify PHP version (5 or 7)
|
||||||
|
|
||||||
(O): Optional
|
(O): Optional
|
||||||
|
|||||||
16
tasks/dyn_modules.yml
Normal file
16
tasks/dyn_modules.yml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
- name: FAIL | If Dynamic module is not available
|
||||||
|
fail: msg="{{ item }} dynamic module is not available"
|
||||||
|
with_items: "{{ nginx_dyn_modules }}"
|
||||||
|
when: "'{{ item }}=dynamic' not in nginx_modules"
|
||||||
|
|
||||||
|
- name: APT | Install nginx modules
|
||||||
|
apt: >
|
||||||
|
pkg="libnginx-mod-{{ item | replace('_', '-') }}"
|
||||||
|
state=present
|
||||||
|
default_release={{ ansible_distribution_release + '-backports' if nginx_backports else ansible_distribution_release }}
|
||||||
|
with_items: "{{ nginx_dyn_modules }}"
|
||||||
|
when: ansible_distribution == 'Debian'
|
||||||
|
|
||||||
|
# TODO: manage freebsd
|
||||||
@@ -17,3 +17,4 @@
|
|||||||
- "{{ nginx_htpasswd }}"
|
- "{{ nginx_htpasswd }}"
|
||||||
- users
|
- users
|
||||||
when: item.0.state is not defined or item.0.state == 'present'
|
when: item.0.state is not defined or item.0.state == 'present'
|
||||||
|
no_log: true
|
||||||
|
|||||||
@@ -9,6 +9,10 @@
|
|||||||
- name: INCLUDE | Prepare
|
- name: INCLUDE | Prepare
|
||||||
include: prepare.yml
|
include: prepare.yml
|
||||||
|
|
||||||
|
- name: INCLUDE | Manage dynamic modules
|
||||||
|
include: dyn_modules.yml
|
||||||
|
when: nginx_version.stdout | version_compare('1.9.11', 'ge')
|
||||||
|
|
||||||
- name: INCLUDE | Install
|
- name: INCLUDE | Install
|
||||||
include: config.yml
|
include: config.yml
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
changed_when: false
|
changed_when: false
|
||||||
|
|
||||||
- name: SHELL | Get module list
|
- name: SHELL | Get module list
|
||||||
shell: nginx -V 2>&1 | tr -- - '\n' | grep -A 1 with | grep _module | sed 's/_module[[:space:]]*//g' | sort
|
shell: nginx -V 2>&1 | tr -- - '\n' | grep -A 1 with | grep _module | sed -r 's/_module//g; s/\s+//g' | sort
|
||||||
args:
|
args:
|
||||||
executable: /bin/sh
|
executable: /bin/sh
|
||||||
register: shell_modules
|
register: shell_modules
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
with_items: "{{ nginx_ssl_pairs }}"
|
with_items: "{{ nginx_ssl_pairs }}"
|
||||||
when: item.key is defined
|
when: item.key is defined
|
||||||
notify: reload nginx
|
notify: reload nginx
|
||||||
|
no_log: true
|
||||||
|
|
||||||
- name: COPY | Deploy SSL certs
|
- name: COPY | Deploy SSL certs
|
||||||
copy: >
|
copy: >
|
||||||
|
|||||||
@@ -5,14 +5,6 @@
|
|||||||
when: item.filename is defined and item.filename == 'default'
|
when: item.filename is defined and item.filename == 'default'
|
||||||
with_items: "{{ nginx_vhosts }}"
|
with_items: "{{ nginx_vhosts }}"
|
||||||
|
|
||||||
- name: FAIL | Check vhost and SSL/TLS support
|
|
||||||
fail: msg="Missmatch configuration for vhost {{ item.name if item.name is string else item.name[0] }}"
|
|
||||||
when: >
|
|
||||||
item.proto is defined and
|
|
||||||
'https' in item.proto and
|
|
||||||
item.ssl_name is not defined
|
|
||||||
with_items: "{{ nginx_vhosts }}"
|
|
||||||
|
|
||||||
- name: FAIL | Check HTTPS redir and proto
|
- name: FAIL | Check HTTPS redir and proto
|
||||||
fail: msg="You can't have HTTP proto and HTTPS redirection at the same time"
|
fail: msg="You can't have HTTP proto and HTTPS redirection at the same time"
|
||||||
when: >
|
when: >
|
||||||
@@ -48,8 +40,10 @@
|
|||||||
when: item.state is not defined or item.state != 'absent'
|
when: item.state is not defined or item.state != 'absent'
|
||||||
|
|
||||||
- name: FILE | Delete vhosts
|
- name: FILE | Delete vhosts
|
||||||
file: path={{ nginx_etc_dir }}/sites-available/{{ item.filename | default(item.name if item.name is string else item.name[0]) }} state=absent
|
file: path={{ nginx_etc_dir }}/{{ item.1 }}/{{ item.0.filename | default(item.0.name if item.0.name is string else item.0.name[0]) }} state=absent
|
||||||
with_items: "{{ nginx_vhosts }}"
|
with_nested:
|
||||||
|
- "{{ nginx_vhosts }}"
|
||||||
|
- ['sites-available', 'sites-enabled']
|
||||||
notify: ['reload nginx', 'restart nginx freebsd']
|
notify: ['reload nginx', 'restart nginx freebsd']
|
||||||
when: item.state is defined and item.state == 'absent'
|
when: item.state is defined and item.state == 'absent'
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,11 @@
|
|||||||
user {{ nginx_user }};
|
user {{ nginx_user }};
|
||||||
worker_processes {{ nginx_worker_processes }};
|
worker_processes {{ nginx_worker_processes }};
|
||||||
pid {{ nginx_pid }};
|
pid {{ nginx_pid }};
|
||||||
|
{% if nginx_version.stdout | version_compare('1.9.11', 'ge') %}
|
||||||
|
{% for module in nginx_dyn_modules -%}
|
||||||
|
load_module "modules/ngx_{{ module }}_module.so";
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
events {
|
events {
|
||||||
worker_connections {{ nginx_events_worker_connections }};
|
worker_connections {{ nginx_events_worker_connections }};
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
{% set __listen_ssl = item.listen_ssl | default(['443']) %}
|
{% set __listen_ssl = item.listen_ssl | default(['443']) %}
|
||||||
{% set __location = item.location | default({}) %}
|
{% set __location = item.location | default({}) %}
|
||||||
{% set __headers = item.headers | default({'X-Frame-Options': 'DENY always', 'X-Content-Type-Options': 'nosniff always' }) %}
|
{% set __headers = item.headers | default({'X-Frame-Options': 'DENY always', 'X-Content-Type-Options': 'nosniff always' }) %}
|
||||||
|
{% set __ssl_name = item.ssl_name | default(item.name if item.name is string else item.name[0]) %}
|
||||||
|
{% set __location_order = item.location_order | default(__location.keys()) %}
|
||||||
{% macro htpasswd(htpasswd_name, indent=1) -%}
|
{% macro htpasswd(htpasswd_name, indent=1) -%}
|
||||||
{% for ht in nginx_htpasswd if ht.name == htpasswd_name %}
|
{% for ht in nginx_htpasswd if ht.name == htpasswd_name %}
|
||||||
{{ "\t" * indent }}auth_basic "{{ ht.description }}";
|
{{ "\t" * indent }}auth_basic "{{ ht.description }}";
|
||||||
@@ -33,7 +35,7 @@ server {
|
|||||||
{% for port in __listen_ssl %}
|
{% for port in __listen_ssl %}
|
||||||
listen {{ port }}{% if nginx_default_vhost_ssl == __main_name %} default_server{% endif %} ssl{% if nginx_auto_config_httpv2 and 'http_v2' in nginx_modules %} http2{% endif %};
|
listen {{ port }}{% if nginx_default_vhost_ssl == __main_name %} default_server{% endif %} ssl{% if nginx_auto_config_httpv2 and 'http_v2' in nginx_modules %} http2{% endif %};
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{{ ssl(item.ssl_name) }}
|
{{ ssl(__ssl_name) }}
|
||||||
{% if item.ssl_template is not defined or item.ssl_template != false %}
|
{% if item.ssl_template is not defined or item.ssl_template != false %}
|
||||||
include {{ nginx_helper_dir + '/ssl-' + item.ssl_template | default('strong') }};
|
include {{ nginx_helper_dir + '/ssl-' + item.ssl_template | default('strong') }};
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@@ -83,10 +85,11 @@ server {
|
|||||||
{% block template_custom_location %}
|
{% block template_custom_location %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% if __location is iterable and __location | length > 0 %}
|
{% if __location_order | length > 0 %}
|
||||||
# --> Custom locations
|
# --> Custom locations
|
||||||
{% for location, opts in __location.iteritems() %}
|
{% for location in __location_order %}
|
||||||
location {{ location }} {
|
location {{ location }} {
|
||||||
|
{% set opts = __location[location] %}
|
||||||
{% for opt in opts %}
|
{% for opt in opts %}
|
||||||
{% if opt.htpasswd is defined %}{{ htpasswd(opt.htpasswd, 2) }}{% else %}
|
{% if opt.htpasswd is defined %}{{ htpasswd(opt.htpasswd, 2) }}{% else %}
|
||||||
{{ opt }}
|
{{ opt }}
|
||||||
@@ -137,10 +140,10 @@ server {
|
|||||||
#
|
#
|
||||||
server {
|
server {
|
||||||
{% for port in __listen %}
|
{% for port in __listen %}
|
||||||
listen {{ port }};
|
listen {{ port }}{% if nginx_default_vhost == __main_name %} default_server{% endif %};
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
server_name {% if item.name is string %}{{ item.name }}{% else %}{{ item.name | join(' ') }}{% endif %};
|
server_name {% if item.name is string %}{{ item.name }}{% else %}{{ "\n\t\t" }}{{ item.name | join("\n\t\t") }}{% endif %};
|
||||||
return 301 https://{{ __main_name }}{% if '443' not in __listen_ssl %}:__listen_ssl[0]{% endif %}$request_uri;
|
return 301 https://{{ __main_name }}{% if '443' not in __listen_ssl %}:{{ __listen_ssl[0] }}{% endif %}$request_uri;
|
||||||
}
|
}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
@@ -153,7 +156,7 @@ server {
|
|||||||
{% for port in __listen %}
|
{% for port in __listen %}
|
||||||
listen {{ port }};
|
listen {{ port }};
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
server_name {{ item.redirect_from | join(' ') }};
|
server_name {% if item.redirect_from is string %}{{ item.redirect_from }}{% else %}{{ "\n\t\t" }}{{ item.redirect_from | join("\n\t\t") }}{% endif %};
|
||||||
return 301 $scheme://{{ __main_name }}$request_uri;
|
return 301 $scheme://{{ __main_name }}$request_uri;
|
||||||
}
|
}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
{% extends "_base.j2" %}
|
{% extends "_base.j2" %}
|
||||||
|
|
||||||
{% macro phpv(version) %}
|
{% macro phpv(version) %}
|
||||||
{% if version == 56 or version == "5.6" %}
|
{% if version == 56 or version == "56" or version == "5.6" %}
|
||||||
{{ nginx_upstream_php56 -}}
|
{{ nginx_upstream_php56 -}}
|
||||||
{% elif version == 70 or version == "7.0" %}
|
{% elif version == 70 or version == "70" or version == "7.0" %}
|
||||||
{{ nginx_upstream_php70 -}}
|
{{ nginx_upstream_php70 -}}
|
||||||
{% else %}
|
{% else %}
|
||||||
{# Hack... define another upstream #}
|
{# Hack... define another upstream #}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
FROM williamyeh/ansible:debian8-onbuild
|
FROM williamyeh/ansible:debian8-onbuild
|
||||||
|
|
||||||
RUN apt-get update
|
RUN apt-get update
|
||||||
CMD ["sh", "tests/test.sh"]
|
CMD ["sh", "tests/travis.sh"]
|
||||||
|
|||||||
@@ -6,13 +6,13 @@
|
|||||||
- block:
|
- block:
|
||||||
- name: APT | Install DotDeb key
|
- name: APT | Install DotDeb key
|
||||||
apt_key: url='http://www.dotdeb.org/dotdeb.gpg' state=present
|
apt_key: url='http://www.dotdeb.org/dotdeb.gpg' state=present
|
||||||
- name: APT_REPOSITORY | Install dotdeb (PHP 7)
|
- name: APT_REPOSITORY | Install dotdeb (PHP 7)
|
||||||
apt_repository: repo='deb http://packages.dotdeb.org {{ ansible_distribution_release }} all' state=present
|
apt_repository: repo='deb http://packages.dotdeb.org {{ ansible_distribution_release }} all' state=present
|
||||||
- name: LINEFILEFILE | Dotdeb priority (prevent install nginx from dotdeb)
|
- name: LINEFILEFILE | Dotdeb priority (prevent install nginx from dotdeb)
|
||||||
copy: >
|
copy: >
|
||||||
content="Package: *\nPin: release o=packages.dotdeb.org\nPin-Priority: 100"
|
content="Package: *\nPin: release o=packages.dotdeb.org\nPin-Priority: 100"
|
||||||
dest=/etc/apt/preferences
|
dest=/etc/apt/preferences
|
||||||
when: ansible_distribution_release == 'jessie'
|
when: ansible_distribution_release == 'jessie' and dotdeb
|
||||||
|
|
||||||
- name: APT | Install needed packages
|
- name: APT | Install needed packages
|
||||||
apt: pkg={{ item }} update_cache=yes cache_valid_time=3600 state=present
|
apt: pkg={{ item }} update_cache=yes cache_valid_time=3600 state=present
|
||||||
@@ -20,17 +20,28 @@
|
|||||||
- curl
|
- curl
|
||||||
- fcgiwrap
|
- fcgiwrap
|
||||||
- nghttp2
|
- nghttp2
|
||||||
- php5-fpm
|
|
||||||
- php5-sqlite
|
|
||||||
- php7.0-fpm
|
|
||||||
- php7.0-sqlite3
|
|
||||||
- strace
|
- strace
|
||||||
- vim
|
- vim
|
||||||
|
|
||||||
- name: SERVICE | Force start services
|
- name: APT | Install PHP5.6
|
||||||
service: name={{ item }} state=started
|
apt: pkg={{ item }} update_cache=yes cache_valid_time=3600 state=present
|
||||||
register: sf
|
|
||||||
with_items:
|
with_items:
|
||||||
- php5-fpm
|
- php5-fpm
|
||||||
|
- php5-sqlite
|
||||||
|
when: nginx_php56
|
||||||
|
|
||||||
|
- name: APT | Install PHP7
|
||||||
|
apt: pkg={{ item }} update_cache=yes cache_valid_time=3600 state=present
|
||||||
|
with_items:
|
||||||
- php7.0-fpm
|
- php7.0-fpm
|
||||||
- fcgiwrap
|
- php7.0-sqlite3
|
||||||
|
when: nginx_php70
|
||||||
|
|
||||||
|
- name: SERVICE | Force start services
|
||||||
|
service: name={{ item.name }} state=started
|
||||||
|
register: sf
|
||||||
|
with_items:
|
||||||
|
- { name: 'php5-fpm', cond: "{{ nginx_php56 }}" }
|
||||||
|
- { name: 'php7.0-fpm', cond: "{{ nginx_php70 }}" }
|
||||||
|
- { name: 'fcgiwrap', cond: true }
|
||||||
|
when: "{{ item.cond }}"
|
||||||
|
|||||||
@@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
- hosts: all
|
- hosts: all
|
||||||
pre_tasks:
|
pre_tasks:
|
||||||
|
- debug: var=dotdeb
|
||||||
|
- debug: var=nginx_php56
|
||||||
|
- debug: var=nginx_php70
|
||||||
|
- debug: var=nginx_backports
|
||||||
- name: INCLUDE | Pre_tasks related to OS version
|
- name: INCLUDE | Pre_tasks related to OS version
|
||||||
include: "includes/pre_{{ ansible_distribution }}.yml"
|
include: "includes/pre_{{ ansible_distribution }}.yml"
|
||||||
- name: FILE | Create an internal SSL dir
|
- name: FILE | Create an internal SSL dir
|
||||||
@@ -16,9 +20,7 @@
|
|||||||
# 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_backports: true
|
nginx_dyn_modules: ['http_geoip']
|
||||||
nginx_php56: true
|
|
||||||
nginx_php70: true
|
|
||||||
nginx_upstreams:
|
nginx_upstreams:
|
||||||
- name: 'test'
|
- name: 'test'
|
||||||
servers:
|
servers:
|
||||||
@@ -106,6 +108,13 @@
|
|||||||
-----END CERTIFICATE-----
|
-----END CERTIFICATE-----
|
||||||
nginx_custom_http:
|
nginx_custom_http:
|
||||||
- 'add_header X-ansible 1;'
|
- 'add_header X-ansible 1;'
|
||||||
|
- 'geoip_country /usr/share/GeoIP/GeoIP.dat;'
|
||||||
|
- 'map $geoip_country_code $allowed_country {'
|
||||||
|
- ' default yes;'
|
||||||
|
- ' MA no;'
|
||||||
|
- ' DZ no;'
|
||||||
|
- ' TN no;'
|
||||||
|
- '}'
|
||||||
nginx_default_vhost: 'first-test'
|
nginx_default_vhost: 'first-test'
|
||||||
nginx_default_vhost_ssl: 'test-ssl-predeployed.local'
|
nginx_default_vhost_ssl: 'test-ssl-predeployed.local'
|
||||||
nginx_vhosts:
|
nginx_vhosts:
|
||||||
@@ -146,8 +155,19 @@
|
|||||||
location:
|
location:
|
||||||
'/':
|
'/':
|
||||||
- 'alias /var/tmp;'
|
- 'alias /var/tmp;'
|
||||||
|
'/a':
|
||||||
|
- 'alias /var/tmp;'
|
||||||
|
'/b':
|
||||||
|
- 'alias /var/tmp;'
|
||||||
|
'/c':
|
||||||
|
- 'alias /var/tmp;'
|
||||||
|
location_order:
|
||||||
|
- '/'
|
||||||
|
- '/a'
|
||||||
|
- '/b'
|
||||||
|
- '/c'
|
||||||
- name: 'test-php.local'
|
- name: 'test-php.local'
|
||||||
php_version: 70
|
php_version: "{{ '7.0' if nginx_php70 else '5.6' }}"
|
||||||
upstream_params:
|
upstream_params:
|
||||||
- 'fastcgi_param FOO bar;'
|
- 'fastcgi_param FOO bar;'
|
||||||
redirect_from:
|
redirect_from:
|
||||||
@@ -177,7 +197,6 @@
|
|||||||
- name: 'test-ssl.local'
|
- name: 'test-ssl.local'
|
||||||
proto: ['http', 'https']
|
proto: ['http', 'https']
|
||||||
template: '_base'
|
template: '_base'
|
||||||
ssl_name: 'test-ssl.local'
|
|
||||||
- name: 'test-ssl-predeployed.local'
|
- name: 'test-ssl-predeployed.local'
|
||||||
proto: ['http', 'https']
|
proto: ['http', 'https']
|
||||||
template: '_base'
|
template: '_base'
|
||||||
@@ -238,19 +257,13 @@
|
|||||||
# --------------------------------
|
# --------------------------------
|
||||||
# PHP
|
# PHP
|
||||||
# --------------------------------
|
# --------------------------------
|
||||||
- name: -- VERIFY PHP VHOSTS --
|
|
||||||
command: "curl -H 'Host: {{ item }}' http://127.0.0.1/"
|
|
||||||
register: p
|
|
||||||
changed_when: false
|
|
||||||
failed_when: p.stdout.find('PHP Version') == -1
|
|
||||||
with_items: ['test-php.local', 'test-php-index.local']
|
|
||||||
|
|
||||||
- name: -- VERIFY PHP5 VHOSTS (implicit default) --
|
- name: -- VERIFY PHP5 VHOSTS (implicit default) --
|
||||||
command: "curl -H 'Host: {{ item }}' http://127.0.0.1/"
|
command: "curl -H 'Host: {{ item }}' http://127.0.0.1/"
|
||||||
register: p
|
register: p
|
||||||
changed_when: false
|
changed_when: false
|
||||||
failed_when: p.stdout.find('PHP Version 5') == -1
|
failed_when: p.stdout.find('PHP Version 5') == -1
|
||||||
with_items: ['test-php-index.local']
|
with_items: ['test-php-index.local']
|
||||||
|
when: nginx_php56
|
||||||
|
|
||||||
- name: -- VERIFY PHP7 VHOSTS --
|
- name: -- VERIFY PHP7 VHOSTS --
|
||||||
command: "curl -H 'Host: {{ item }}' http://127.0.0.1/"
|
command: "curl -H 'Host: {{ item }}' http://127.0.0.1/"
|
||||||
@@ -258,6 +271,7 @@
|
|||||||
changed_when: false
|
changed_when: false
|
||||||
failed_when: p.stdout.find('PHP Version 7') == -1
|
failed_when: p.stdout.find('PHP Version 7') == -1
|
||||||
with_items: ['test-php.local']
|
with_items: ['test-php.local']
|
||||||
|
when: nginx_php70
|
||||||
|
|
||||||
# --------------------------------
|
# --------------------------------
|
||||||
# Basic Auth
|
# Basic Auth
|
||||||
|
|||||||
@@ -5,16 +5,21 @@
|
|||||||
DIR=$( dirname $0 )
|
DIR=$( dirname $0 )
|
||||||
PLAYBOOK="$DIR/test.yml"
|
PLAYBOOK="$DIR/test.yml"
|
||||||
|
|
||||||
|
|
||||||
set -ev
|
set -ev
|
||||||
|
|
||||||
|
ANSIBLE_VARS="{ nginx_php56: $NGINX_PHP56, nginx_php70: $NGINX_PHP70, nginx_backports: $NGINX_BACKPORTS, dotdeb: $DOTDEB }"
|
||||||
|
|
||||||
|
echo $ANSIBLE_VARS
|
||||||
|
|
||||||
# Check syntax
|
# Check syntax
|
||||||
ansible-playbook -i localhost, -c local --syntax-check -vv $PLAYBOOK
|
ansible-playbook -i localhost, -c local --syntax-check -vv $PLAYBOOK
|
||||||
|
|
||||||
# Check role
|
# Check role
|
||||||
ansible-playbook -i localhost, -c local --sudo -vv $PLAYBOOK
|
ansible-playbook -i localhost, -c local -e "$ANSIBLE_VARS" --sudo -vv $PLAYBOOK
|
||||||
|
|
||||||
# Check indempotence
|
# Check indempotence
|
||||||
ansible-playbook -i localhost, -c local --sudo -vv $PLAYBOOK \
|
ansible-playbook -i localhost, -c local -e "$ANSIBLE_VARS" --sudo -vv $PLAYBOOK \
|
||||||
| grep -q 'changed=0.*failed=0' \
|
| grep -q 'changed=0.*failed=0' \
|
||||||
&& (echo 'Idempotence test: pass' && exit 0) \
|
&& (echo 'Idempotence test: pass' && exit 0) \
|
||||||
|| (echo 'Idempotence test: fail' && exit 1)
|
|| (echo 'Idempotence test: fail' && exit 1)
|
||||||
Reference in New Issue
Block a user