-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·67 lines (49 loc) · 1.58 KB
/
build.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
#!/bin/sh
set -e
if [ "$1" = "vagrant" ]
then
echo "Vagrant..."
INVENTORY_FILE=vagrant-inventory
vagrant up
elif [ "$1" = "local" ]
then
echo "Local..."
INVENTORY_FILE=local-inventory
else
echo "First argument is not defined properly. Choose [ vagrant | local ] ..."
exit
fi
# Step 1:
echo ">>> Step 1: Install required dependencies roles."
ansible-galaxy install -r ansible_requirements.txt --force
# Step 2:
echo ">>> Step 2: check role/playbook syntax"
ansible-playbook -i ${INVENTORY_FILE} playbook.yml --syntax-check
# Step 3:
echo ">>> Step 3: run the role/playbook with ansible-playbook"
ansible-playbook -i ${INVENTORY_FILE} playbook.yml
if [ "$2" = "skip" ]
then
exit 0
fi
# Step 4:
echo ">>> Step 4: run the role/playbook again, checking to make sure it's idempotent."
echo ">>> Ansible..."
ansible-playbook -i ${INVENTORY_FILE} playbook.yml > out.txt 2>&1
cat out.txt
cat out.txt | grep -q 'changed=0.*failed=0'\
&& (echo 'Idempotence test: Success' && rm out.txt && exit 0) || (echo 'Idempotence test: Fail' && rm out.txt && exit 1)
if [ "$1" = "vagrant" ]
then
# Step 5:
echo ">>> Step 5: run the role/playbook again, after machine reboot to make sure it's idempotent as well =)"
vagrant reload
echo ">>> Ansible..."
ansible-playbook -i ${INVENTORY_FILE} playbook.yml > out.txt 2>&1
cat out.txt
cat out.txt | grep -q 'changed=0.*failed=0'\
&& (echo 'Idempotence test after reboot: Success' && rm out.txt && exit 0) || (echo 'Idempotence test after reboot: Fail' && rm out.txt && exit 1)
fi
echo "=================="
echo "SUCCESS"
echo "=================="