2015-07-23 21:35:25 +07:00
|
|
|
#!/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"
|
2016-01-22 23:17:38 +07:00
|
|
|
ANSIBLE_ARG="localhost"
|
2015-07-23 21:35:25 +07:00
|
|
|
|
|
|
|
set -ev
|
|
|
|
|
2016-01-22 22:29:43 +07:00
|
|
|
# Only for travis
|
|
|
|
if [ -n "$1" ]
|
|
|
|
then
|
2016-01-22 23:17:38 +07:00
|
|
|
ANSIBLE_ARG="--limit $1"
|
2016-01-22 22:29:43 +07:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
ansible --version
|
|
|
|
|
2015-07-23 21:35:25 +07:00
|
|
|
# Check syntax
|
2016-01-22 22:57:32 +07:00
|
|
|
ansible-playbook -i $INVENTORY_FILE -c local $ANSIBLE_ARG --syntax-check -vv $PLAYBOOK
|
2015-07-23 21:35:25 +07:00
|
|
|
|
|
|
|
# Check role
|
2016-01-22 22:29:43 +07:00
|
|
|
ansible-playbook -i $INVENTORY_FILE -c local $ANSIBLE_ARG --become -vv $PLAYBOOK
|
2015-07-23 21:35:25 +07:00
|
|
|
|
|
|
|
# Check indempotence
|
2016-01-22 22:29:43 +07:00
|
|
|
ansible-playbook -i $INVENTORY_FILE -c local $ANSIBLE_ARG --become -vv $PLAYBOOK \
|
2015-07-23 21:35:25 +07:00
|
|
|
| grep -q 'changed=0.*failed=0' \
|
|
|
|
&& (echo 'Idempotence test: pass' && exit 0) \
|
|
|
|
|| (echo 'Idempotence test: fail' && exit 1)
|