From 60a368f3e112d585ce957e9505ec842960486fc4 Mon Sep 17 00:00:00 2001 From: Emilien Mantel Date: Thu, 13 Oct 2016 10:19:24 +0200 Subject: [PATCH] Manage many configurations --- .travis.yml | 11 ++++++-- Vagrantfile | 23 +++++++-------- templates/etc/nginx/sites-available/_php.j2 | 4 +-- tests/debian-jessie.Dockerfile | 2 +- tests/includes/pre_Debian.yml | 31 ++++++++++++++------- tests/test.yml | 18 +++++------- tests/{test.sh => travis.sh} | 9 ++++-- 7 files changed, 58 insertions(+), 40 deletions(-) rename tests/{test.sh => travis.sh} (56%) diff --git a/.travis.yml b/.travis.yml index da5a8d0..245d551 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,20 @@ -env: - - PLATFORM=debian-jessie +matrix: + 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 +dist: trusty + language: python services: - docker 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: webhooks: https://galaxy.ansible.com/api/v1/notifications/ diff --git a/Vagrantfile b/Vagrantfile index e0cd80a..23aac13 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -6,12 +6,14 @@ Vagrant.configure("2") do |config| vms_debian = [ - [ "debian-jessie", "debian/jessie64" ], - [ "debian-stretch", "sharlak/debian_stretch_64" ] + { :name => "debian-jessie", :box => "debian/jessie64", :vars => { "nginx_php56": true, "nginx_php70": false, "dotdeb": false, "nginx_backports": false }}, + { :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 = [ - [ "freebsd-10.2", "freebsd/FreeBSD-10.2-STABLE" ] + { :name => "freebsd-10.2", :box => "freebsd/FreeBSD-10.2-STABLE" } ] config.vm.provider "virtualbox" do |v| @@ -19,22 +21,22 @@ Vagrant.configure("2") do |config| v.memory = 256 end - vms_debian.each do |vm| - config.vm.define vm[0] do |m| - m.vm.box = vm[1] + vms_debian.each do |opts| + config.vm.define opts[:name] do |m| + m.vm.box = opts[:box] m.vm.network "private_network", type: "dhcp" m.vm.provision "ansible" do |ansible| ansible.playbook = "tests/test.yml" - ansible.groups = { "test" => [ vm[0] ] } ansible.verbose = 'vv' ansible.sudo = true + ansible.extra_vars = opts[:vars] end end end # See: https://forums.freebsd.org/threads/52717/ - vms_freebsd.each do |vm| - config.vm.define vm[0] do |m| - m.vm.box = vm[1] + vms_freebsd.each do |opts| + config.vm.define opts[:name] do |m| + m.vm.box = opts[:box] m.vm.network "private_network", type: "dhcp" m.vm.guest = :freebsd 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 "ansible" do |ansible| ansible.playbook = "tests/test.yml" - ansible.groups = { "test" => [ vm[0] ] } ansible.verbose = 'vv' ansible.sudo = true ansible.extra_vars = { diff --git a/templates/etc/nginx/sites-available/_php.j2 b/templates/etc/nginx/sites-available/_php.j2 index 51b96ad..41b6bfc 100644 --- a/templates/etc/nginx/sites-available/_php.j2 +++ b/templates/etc/nginx/sites-available/_php.j2 @@ -1,9 +1,9 @@ {% extends "_base.j2" %} {% macro phpv(version) %} -{% if version == 56 or version == "5.6" %} +{% if version == 56 or version == "56" or version == "5.6" %} {{ nginx_upstream_php56 -}} -{% elif version == 70 or version == "7.0" %} +{% elif version == 70 or version == "70" or version == "7.0" %} {{ nginx_upstream_php70 -}} {% else %} {# Hack... define another upstream #} diff --git a/tests/debian-jessie.Dockerfile b/tests/debian-jessie.Dockerfile index cd78566..03252b3 100644 --- a/tests/debian-jessie.Dockerfile +++ b/tests/debian-jessie.Dockerfile @@ -1,4 +1,4 @@ FROM williamyeh/ansible:debian8-onbuild RUN apt-get update -CMD ["sh", "tests/test.sh"] +CMD ["sh", "tests/travis.sh"] diff --git a/tests/includes/pre_Debian.yml b/tests/includes/pre_Debian.yml index d3eb893..29f758a 100644 --- a/tests/includes/pre_Debian.yml +++ b/tests/includes/pre_Debian.yml @@ -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 }}" diff --git a/tests/test.yml b/tests/test.yml index 1842af6..2929739 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -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 diff --git a/tests/test.sh b/tests/travis.sh similarity index 56% rename from tests/test.sh rename to tests/travis.sh index 4aee411..cad6b3a 100644 --- a/tests/test.sh +++ b/tests/travis.sh @@ -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)