-
Notifications
You must be signed in to change notification settings - Fork 1
/
play.sh
executable file
·68 lines (62 loc) · 1.7 KB
/
play.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
if [ -z $ANSIBLE_ENVIRONMENT ]; then
echo "ANSIBLE_ENVIRONMENT isn't set; source from {environment}/env.sh"
echo "Example: . vagrant/env.sh"
exit 1
fi
cd $(dirname "$0")
CYAN='\033[0;36m'
RED='\033[0;31m'
YELLOW='\033[0;33m'
GREY='\033[0;90m'
NC='\033[0m'
echo_cmd="echo -e"
$echo_cmd $CYAN
./print-logo.sh
$echo_cmd
./list-env.sh
$echo_cmd $NC
if [ "$DRIFTER_DURATION" == "" ]; then
$echo_cmd "${GREY}Infinite duration${NC}"
DRIFTER_DURATION=2147483647
fi
init_time=`date +%s`
cd ansible
while [ true ]; do
$echo_cmd "Starting run on $(date)"
start_time=`date +%s`
if [ "$DRIFTER_VERBOSE" == "true" ]; then
ansible-playbook playbook.yaml --forks=100 -i inventory.sh -vvv
else
ansible-playbook playbook.yaml --forks=100 -i inventory.sh
fi
exit_code=$?
if [ "$exit_code" == "99" ]; then
$echo_cmd "${YELLOW}Drifter interrupted; exiting.${NC}"
exit 130
elif [ "$exit_code" != "0" ]; then
$echo_cmd "${RED}BUILD FAILED${NC} (Ansible code ${exit_code}); wrapping up."
cd ..
out_dir=out
if [ -d $out_dir ]; then
node_dirs=`find $out_dir -mindepth 1 -maxdepth 1 -type d`
for node_dir in $node_dirs; do
if [ -f ${node_dir}/latest.tgz ]; then
latest_timestamp=`cat ${node_dir}/latest-timestamp`
target_file=${node_dir}/${latest_timestamp}.tgz
$echo_cmd "${GREY}Storing output in ${target_file}${NC}"
mv ${node_dir}/latest.tgz $target_file
fi
done
fi
exit 1;
else
end_time=`date +%s`
took=$((end_time - start_time))
$echo_cmd "${CYAN}Took $took seconds.${NC}"
total_time=$((end_time - init_time))
if [ $total_time -gt $DRIFTER_DURATION ]; then
exit 0
fi
fi
done