-
Notifications
You must be signed in to change notification settings - Fork 2
/
start.sh
executable file
·150 lines (131 loc) · 3.88 KB
/
start.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/bash
# With LANG set to everything else than C completely undercipherable errors
# like "file not found" and decoding errors will start to appear during scripts
# or even ansible modules
LANG=C
GREM_DIR=$(dirname $( readlink -f "${BASH_SOURCE[0]}" ))
DEFAULT_OPT_TAGS="untagged"
: ${OPT_TAGS:=$DEFAULT_OPT_TAGS}
: ${OPT_PLAYBOOK:=$GREM_DIR/playbooks/hello.yml}
: ${OPT_CONFIG:=$GREM_DIR/config.yml}
install_deps () {
sudo yum clean all
sudo yum makecache
sudo yum -y install ansible
}
usage () {
echo "Usage: $0 --install-deps"
echo " install quickstart package dependencies and exit"
echo ""
echo "Usage: $0 [options]"
echo ""
echo "Basic options:"
echo " -p, --playbook <file>"
echo " playbook to run(default=$OPT_PLAYBOOK)"
echo " -i, --inventory <file>"
echo " specify inventory host path"
echo " (default=./inventory/hosts) or comma separated host list"
echo " -c, --config <file>"
echo " specify the config file that contains the node"
echo " configuration, can be used only once"
echo " (default=$OPT_CONFIG)"
echo " -S, --step"
echo " execute playbooks or tasks step by step"
echo " --syntax-check"
echo " perform a syntax check on the playbook, but do not"
echo " execute it"
echo ""
echo "Advanced options:"
echo " -v, --ansible-debug"
echo " invoke ansible-playbook with -vvvv"
echo " -e, --extra-vars <key>=<value>"
echo " additional ansible variables, can be used multiple times"
echo " -t, --tags <tag1>[,<tag2>,...]"
echo " only run plays and tasks tagged with these values,"
echo " specify 'all' to run everything"
echo " (default=$OPT_TAGS)"
echo " -s, --skip-tags <tag1>[,<tag2>,...]"
echo " only run plays and tasks whose tags do"
echo " not match these values"
echo " -h, --help print this help and exit"
}
OPT_VARS=()
while [ "x$1" != "x" ]; do
case "$1" in
--install-deps)
OPT_INSTALL_DEPS=1
;;
--inventory|-i)
OPT_INVENTORY=$2
shift
;;
--playbook|-p)
OPT_PLAYBOOK=$2
shift
;;
--extra-vars|-e)
OPT_VARS+=("-e")
OPT_VARS+=("$2")
shift
;;
--config|-c)
OPT_CONFIG=$2
shift
;;
--step|-s)
OPT_STEP=1
;;
--syntax-check)
OPT_SYNTAX_CHECK=1
;;
--ansible-debug|-v)
OPT_DEBUG_ANSIBLE=1
;;
--tags|-t)
OPT_TAGS=$2
shift
;;
--skip-tags|-S)
OPT_SKIP_TAGS=$2
shift
;;
--help|-h)
usage
exit
;;
--)
shift
break
;;
*)
break
;;
esac
shift
done
if [ "$OPT_INSTALL_DEPS" = 1 ]; then
echo "NOTICE: installing dependencies"
install_deps
exit $?
fi
if [ "$#" -gt 2 ]; then
usage >&2
exit 2
fi
set -ex
export ANSIBLE_CONFIG=$GREM_DIR/ansible.cfg
export ANSIBLE_INVENTORY=$GREM_DIR/inventory/hosts
if [ "$OPT_DEBUG_ANSIBLE" = 1 ]; then
VERBOSITY=vvvv
else
VERBOSITY=vv
fi
ansible-playbook -$VERBOSITY $OPT_PLAYBOOK \
-e @$OPT_CONFIG \
${OPT_VARS[@]} \
${OPT_INVENTORY:+-i $OPT_INVENTORY} \
${OPT_TAGS:+-t $OPT_TAGS} \
${OPT_SKIP_TAGS:+--skip-tags $OPT_SKIP_TAGS} \
${OPT_STEP:+--step} \
${OPT_SYNTAX_CHECK:+--syntax-check}
set +x