Vagrant + tests

pull/5/head
Emilien Mantel 2015-07-23 16:35:25 +02:00
parent 5e0e938038
commit 3d043ac20d
6 changed files with 70 additions and 0 deletions

31
Vagrantfile vendored 100644
View File

@ -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.87" ],
[ "debian-jessie", "deb/jessie-amd64", "192.168.33.88" ]
]
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

View File

@ -0,0 +1,6 @@
FROM williamyeh/ansible:debian8-onbuild
RUN apt-get update
CMD ["sh", "tests/test.sh"]
EXPOSE 6379

View File

@ -0,0 +1,6 @@
FROM williamyeh/ansible:debian7-onbuild
RUN apt-get update
CMD ["sh", "tests/test.sh"]
EXPOSE 6379

1
tests/inventory 100644
View File

@ -0,0 +1 @@
localhost

21
tests/test.sh 100644
View File

@ -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)

5
tests/test.yml 100644
View File

@ -0,0 +1,5 @@
---
- hosts: all
roles:
- ../../