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
|
|
|
ansible --version
|
|
|
|
|
2015-07-23 21:35:25 +07:00
|
|
|
# Check syntax
|
2016-03-04 13:48:52 +07:00
|
|
|
ansible-playbook -i $INVENTORY_FILE -c local --syntax-check -vv $PLAYBOOK
|
2015-07-23 21:35:25 +07:00
|
|
|
|
|
|
|
# Check role
|
2016-03-04 13:48:52 +07:00
|
|
|
ansible-playbook -i $INVENTORY_FILE -c local -e "php_version: $1" --become -vv $PLAYBOOK
|
2015-07-23 21:35:25 +07:00
|
|
|
|
|
|
|
# Check indempotence
|
2016-03-04 13:48:52 +07:00
|
|
|
ansible-playbook -i $INVENTORY_FILE -c local -e "php_version: $1" --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)
|