From 0627d4424cff9a6bb51cd44037a9a3456c4550bf Mon Sep 17 00:00:00 2001 From: Emilien Mantel Date: Sun, 12 Jul 2015 12:15:59 +0200 Subject: [PATCH] Import tests and vagrant --- Vagrantfile | 31 +++++++++++++++++++++++++++++++ tests/debian-jessie.Dockerfile | 4 ++++ tests/debian-wheezy.Dockerfile | 4 ++++ tests/inventory | 1 + tests/test.sh | 21 +++++++++++++++++++++ tests/test.yml | 5 +++++ 6 files changed, 66 insertions(+) create mode 100644 Vagrantfile create mode 100644 tests/debian-jessie.Dockerfile create mode 100644 tests/debian-wheezy.Dockerfile create mode 100644 tests/inventory create mode 100644 tests/test.sh create mode 100644 tests/test.yml diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..4bd2c6c --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,31 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : +# vi: set tabstop=2 : +# vi: set shiftwidth=2 : + +Vagrant.configure("2") do |config| + + vms = [ + [ "debian-wheezy", "deb/wheezy-amd64" , "192.168.33.29" ], + [ "debian-jessie", "deb/jessie-amd64", "192.168.33.30" ] + ] + + config.vm.provider "virtualbox" do |v| + v.cpus = 1 + v.memory = 256 + end + + vms.each do |vm| + config.vm.define vm[0] do |m| + m.vm.box = vm[1] + m.vm.network "private_network", ip: vm[2] + + m.vm.provision "ansible" do |ansible| + ansible.playbook = "tests/test.yml" + ansible.groups = { "test" => [ vm[0] ] } + ansible.verbose = 'vv' + ansible.sudo = true + end + end + end +end diff --git a/tests/debian-jessie.Dockerfile b/tests/debian-jessie.Dockerfile new file mode 100644 index 0000000..cd78566 --- /dev/null +++ b/tests/debian-jessie.Dockerfile @@ -0,0 +1,4 @@ +FROM williamyeh/ansible:debian8-onbuild + +RUN apt-get update +CMD ["sh", "tests/test.sh"] diff --git a/tests/debian-wheezy.Dockerfile b/tests/debian-wheezy.Dockerfile new file mode 100644 index 0000000..bc45db9 --- /dev/null +++ b/tests/debian-wheezy.Dockerfile @@ -0,0 +1,4 @@ +FROM williamyeh/ansible:debian7-onbuild + +RUN apt-get update +CMD ["sh", "tests/test.sh"] diff --git a/tests/inventory b/tests/inventory new file mode 100644 index 0000000..2fbb50c --- /dev/null +++ b/tests/inventory @@ -0,0 +1 @@ +localhost diff --git a/tests/test.sh b/tests/test.sh new file mode 100644 index 0000000..e14025a --- /dev/null +++ b/tests/test.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +# Thanks to https://servercheck.in/blog/testing-ansible-roles-travis-ci-github + +DIR=$( dirname $0 ) +INVENTORY_FILE="$DIR/inventory" +PLAYBOOK="$DIR/test.yml" + +set -ev + +# Check syntax +ansible-playbook -i $INVENTORY_FILE -c local --syntax-check -vv $PLAYBOOK + +# Check role +ansible-playbook -i $INVENTORY_FILE -c local --sudo -vv $PLAYBOOK + +# Check indempotence +ansible-playbook -i $INVENTORY_FILE -c local --sudo -vv $PLAYBOOK \ +| grep -q 'changed=0.*failed=0' \ +&& (echo 'Idempotence test: pass' && exit 0) \ +|| (echo 'Idempotence test: fail' && exit 1) diff --git a/tests/test.yml b/tests/test.yml new file mode 100644 index 0000000..41c410b --- /dev/null +++ b/tests/test.yml @@ -0,0 +1,5 @@ +--- + +- hosts: all + roles: + - ../../