3
3
#
4
4
# Bash script to run idempotence tests.
5
5
#
6
- # version: 1.4
6
+ # version: 1.5
7
7
#
8
8
# usage:
9
9
#
23
23
#
24
24
# # on a Vagrant box
25
25
# bash test_idempotence.sh \
26
- # --box precise64.vagrant.dev
26
+ # --box precise64.vagrant.dev \
27
27
# --inventory .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory
28
28
#
29
29
#
30
30
# changelog:
31
31
#
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
32
35
# v1.4 : 10 Jul 2015
33
36
# - added extra variables to force running idempotence tests on vagrant
34
37
# v1.2
@@ -47,7 +50,7 @@ RED='\033[0;31m'
47
50
# SGR code to set text color (foreground) to no color.
48
51
NC=' \033[0m'
49
52
# The idempotence pass criteria.
50
- PASS_CRITERIA=" changed=0.*unreachable=0.*failed=0"
53
+ PASS_CRITERIA=" changed=0.* unreachable=0.* failed=0"
51
54
52
55
# the name of the virtualenv
53
56
VIRTUALENV_NAME=$( which python | awk -F / ' NF && NF-2 { print ( $(NF-2) ) }' )
89
92
90
93
# the name of the Vagrant box or host name
91
94
BOX=${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 ' }
94
97
# the path to the Ansible test playbook
95
98
PLAYBOOK=${PLAYBOOK:- test.yml}
96
99
# 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"
98
101
99
102
EXTRA_ARGS=' '
100
103
if [ $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"
102
106
else
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} "
104
108
fi
105
109
106
110
echo " [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} | \
108
114
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