ansible-php/tests/test.sh

32 lines
718 B
Bash
Raw Normal View History

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