-
Notifications
You must be signed in to change notification settings - Fork 0
/
ansible-run.sh
executable file
·48 lines (40 loc) · 1.26 KB
/
ansible-run.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
#!/bin/bash
usage () {
cat << EOF
Usage:
toolbox_config [ control | $USER ]
EOF
}
echo $1
[[ -z $1 ]] && usage && exit 1
[[ $1 != "control" ]] && [[ $1 != $USER ]] && usage && exit 1
#[[ ( $1 != "control" ) || ( $1 != $USER ) ]] && usage && exit 1
[[ $1 == "control" ]] && PLAYBOOK=$1
[[ $1 == $USER ]] && PLAYBOOK="user"
curl 169.254.169.254/0.1/meta-data/service-accounts 2>&1 | grep googleapis 2>&1 1>/dev/null
[[ $? == 0 ]] && PLAYBOOK="gcp"
echo $PLAYBOOK
#echo HERE
#CONTAINER=$1
DIRNAME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd)"
# Must be run as none priviledged user
abort() { echo -e "${RED}$* ${NC}" >&2 && exit 1; }
[[ $USER == "root" ]] && abort \
"Can't be run as root, must be run as $SUDO_USER."
echo $PLAYBOOK
HOSTNAME=$(hostname)
# configure control
if [[ $HOSTNAME == "toolbox" ]]; then
cd ${DIRNAME}/ansible
ansible-galaxy install -r requirements.yml
ansible-playbook -e user=${USER} -i ./inventory playbooks/${PLAYBOOK}.yml
cd -
fi
# Is is google
curl 169.254.169.254/0.1/meta-data/service-accounts 2>&1 | grep googleapis 2>&1 1>/dev/null
if [[ $? == 0 ]]; then
cd ${DIRNAME}/ansible
ansible-galaxy install -r requirements.yml
ansible-playbook -e user=${USER} -i ./inventory playbooks/${PLAYBOOK}.yml
cd -
fi