mirror of
https://github.com/HanXHX/ansible-nginx.git
synced 2026-02-24 09:03:29 +07:00
Manage many configurations
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
FROM williamyeh/ansible:debian8-onbuild
|
||||
|
||||
RUN apt-get update
|
||||
CMD ["sh", "tests/test.sh"]
|
||||
CMD ["sh", "tests/travis.sh"]
|
||||
|
||||
@@ -6,13 +6,13 @@
|
||||
- block:
|
||||
- name: APT | Install DotDeb key
|
||||
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
|
||||
- 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'
|
||||
when: ansible_distribution_release == 'jessie' and dotdeb
|
||||
|
||||
- name: APT | Install needed packages
|
||||
apt: pkg={{ item }} update_cache=yes cache_valid_time=3600 state=present
|
||||
@@ -20,17 +20,28 @@
|
||||
- curl
|
||||
- fcgiwrap
|
||||
- nghttp2
|
||||
- php5-fpm
|
||||
- php5-sqlite
|
||||
- php7.0-fpm
|
||||
- php7.0-sqlite3
|
||||
- strace
|
||||
- vim
|
||||
|
||||
- name: SERVICE | Force start services
|
||||
service: name={{ item }} state=started
|
||||
register: sf
|
||||
- name: APT | Install PHP5.6
|
||||
apt: pkg={{ item }} update_cache=yes cache_valid_time=3600 state=present
|
||||
with_items:
|
||||
- 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
|
||||
- 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
|
||||
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
|
||||
include: "includes/pre_{{ ansible_distribution }}.yml"
|
||||
- name: FILE | Create an internal SSL dir
|
||||
@@ -16,9 +20,6 @@
|
||||
# Role vars
|
||||
nginx_worker_processes: 1 # Ansible+FreeBSD can't detect CPU number
|
||||
nginx_apt_package: 'nginx-extras'
|
||||
nginx_backports: true
|
||||
nginx_php56: true
|
||||
nginx_php70: true
|
||||
nginx_dyn_modules: ['http_geoip']
|
||||
nginx_upstreams:
|
||||
- name: 'test'
|
||||
@@ -155,7 +156,7 @@
|
||||
'/':
|
||||
- 'alias /var/tmp;'
|
||||
- name: 'test-php.local'
|
||||
php_version: 70
|
||||
php_version: "{{ '7.0' if nginx_php70 else '5.6' }}"
|
||||
upstream_params:
|
||||
- 'fastcgi_param FOO bar;'
|
||||
redirect_from:
|
||||
@@ -246,19 +247,13 @@
|
||||
# --------------------------------
|
||||
# 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) --
|
||||
command: "curl -H 'Host: {{ item }}' http://127.0.0.1/"
|
||||
register: p
|
||||
changed_when: false
|
||||
failed_when: p.stdout.find('PHP Version 5') == -1
|
||||
with_items: ['test-php-index.local']
|
||||
when: nginx_php56
|
||||
|
||||
- name: -- VERIFY PHP7 VHOSTS --
|
||||
command: "curl -H 'Host: {{ item }}' http://127.0.0.1/"
|
||||
@@ -266,6 +261,7 @@
|
||||
changed_when: false
|
||||
failed_when: p.stdout.find('PHP Version 7') == -1
|
||||
with_items: ['test-php.local']
|
||||
when: nginx_php70
|
||||
|
||||
# --------------------------------
|
||||
# Basic Auth
|
||||
|
||||
@@ -5,16 +5,21 @@
|
||||
DIR=$( dirname $0 )
|
||||
PLAYBOOK="$DIR/test.yml"
|
||||
|
||||
|
||||
set -ev
|
||||
|
||||
ANSIBLE_VARS="{ nginx_php56: $NGINX_PHP56, nginx_php70: $NGINX_PHP70, nginx_backports: $NGINX_BACKPORTS, dotdeb: $DOTDEB }"
|
||||
|
||||
echo $ANSIBLE_VARS
|
||||
|
||||
# Check syntax
|
||||
ansible-playbook -i localhost, -c local --syntax-check -vv $PLAYBOOK
|
||||
|
||||
# Check role
|
||||
ansible-playbook -i localhost, -c local --sudo -vv $PLAYBOOK
|
||||
ansible-playbook -i localhost, -c local -e "$ANSIBLE_VARS" --sudo -vv $PLAYBOOK
|
||||
|
||||
# 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' \
|
||||
&& (echo 'Idempotence test: pass' && exit 0) \
|
||||
|| (echo 'Idempotence test: fail' && exit 1)
|
||||
Reference in New Issue
Block a user