-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·57 lines (46 loc) · 998 Bytes
/
deploy.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
#!/bin/bash
# encoding: UTF-8
# Set default values:
BRANCH=master
# Help message of usage this script.
usage()
{
cat << EOF
Script to deploy puppet in MasterLess mode. You can deploy specific branch and
run in test mode.
usage: $0 [--branch=name]
$0 --branch=IN-1234
OPTIONS:
--branch Specify name of branch in git repository to deploy
EOF
}
while [ $# -gt 0 ]; do
case "$1" in
--branch=*)
BRANCH="${1#*=}"
;;
--help)
usage
exit 0
;;
*)
printf "Error: Invalid argument.\n"
usage
exit 1
esac
shift
done
# Make sure only root can run our script
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
# Deploy ansible:
echo "Deploy branch: ${BRANCH}"
cd /usr/local/etc/ansible || exit 1
/usr/bin/git checkout -f "$BRANCH"
/usr/bin/git fetch origin
/usr/bin/git reset --hard origin/"$BRANCH"
# Run ansible in local mode:
echo "Run ansible..."
/usr/local/bin/ansible-playbook -i hosts servers.yml