33#
44# Bash script to run idempotence tests.
55#
6- # version: 1.4
6+ # version: 1.5
77#
88# usage:
99#
2323#
2424# # on a Vagrant box
2525# bash test_idempotence.sh \
26- # --box precise64.vagrant.dev
26+ # --box precise64.vagrant.dev \
2727# --inventory .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory
2828#
2929#
3030# changelog:
3131#
32+ # v1.5 : 8 Mar 2016
33+ # - pass vagrant_box variable to playbook
34+ # - default inventory changed from localhost to match what Vagrant provisioner generates
3235# v1.4 : 10 Jul 2015
3336# - added extra variables to force running idempotence tests on vagrant
3437# v1.2
@@ -47,7 +50,7 @@ RED='\033[0;31m'
4750# SGR code to set text color (foreground) to no color.
4851NC=' \033[0m'
4952# The idempotence pass criteria.
50- PASS_CRITERIA=" changed=0.*unreachable=0.*failed=0"
53+ PASS_CRITERIA=" changed=0.* unreachable=0.* failed=0"
5154
5255# the name of the virtualenv
5356VIRTUALENV_NAME=$( which python | awk -F / ' NF && NF-2 { print ( $(NF-2) ) }' )
8992
9093# the name of the Vagrant box or host name
9194BOX=${BOX:- localhost}
92- # the Ansible inventory in the form of a file or string "host,"
93- INVENTORY=${INVENTORY:- ' localhost, ' }
95+ # the Ansible inventory
96+ INVENTORY=${INVENTORY:- ' .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory ' }
9497# the path to the Ansible test playbook
9598PLAYBOOK=${PLAYBOOK:- test.yml}
9699# the logfile to hold the output of the playbook run
97- LOGFILE=" log/${BOX} _ ${VIRTUALENV_NAME} .log"
100+ LOGFILE=" log/${BOX} _idempotence_ ${VIRTUALENV_NAME} .log"
98101
99102EXTRA_ARGS=' '
100103if [ $BOX == " localhost" ]; then
101- EXTRA_ARGS=" --connection=local --extra-vars idempotence=yes --extra-vars env=${ENV} "
104+ INVENTORY=' localhost,'
105+ EXTRA_ARGS=" --connection=local -e env=${ENV} -e vagrant_box=localhost"
102106else
103- EXTRA_ARGS=" --u vagrant --extra-vars idempotence=yes --extra-vars env=vagrant "
107+ EXTRA_ARGS=" --user vagrant -e env=vagrant -e vagrant_box= ${BOX} "
104108fi
105109
106110echo " [INFO] ${BOX} ${VIRTUALENV_NAME} running idempotence test..."
107- ansible-playbook -i ${INVENTORY} --limit ${BOX} , ${EXTRA_ARGS} ${PLAYBOOK} 2>&1 | tee ${LOGFILE} | \
111+ IDEMPOTENCE=' yes' \
112+ ansible-playbook -vvvv -i ${INVENTORY} --limit ${BOX} , ${EXTRA_ARGS} ${PLAYBOOK} 2>&1 | \
113+ tee ${LOGFILE} | \
108114 grep " ${BOX} " | grep -q " ${PASS_CRITERIA} " && \
109- echo -ne " [TEST] ${BOX} ${VIRTUALENV_NAME} idempotence : ${GREEN} PASS${NC} \n" || \
110- (echo -ne " [TEST] ${BOX} ${VIRTUALENV_NAME} idempotence : ${RED} FAILED${NC} ${PASS_CRITERIA} \n" && cat ${LOGFILE} && exit 1)
115+ echo -ne " [TEST] ${BOX} ${VIRTUALENV_NAME} idempotence : ${GREEN} PASS${NC} \n" || ( \
116+ cat ${LOGFILE} &&
117+ echo -ne " [TEST] ${BOX} ${VIRTUALENV_NAME} idempotence : ${RED} FAILED${NC} ${PASS_CRITERIA} \n" && \
118+ exit 1)
0 commit comments