Import tests and vagrant

pull/6/head
Emilien Mantel 2015-07-12 12:15:59 +02:00
parent 4e7528300e
commit 0627d4424c
6 changed files with 66 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.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

View File

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

View File

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

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:
- ../../