-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsurf-run-command
executable file
·70 lines (61 loc) · 1.15 KB
/
surf-run-command
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
#!/bin/bash
# run command on all specified hosts
set -e
DIR=$(dirname $0)
cd $DIR
ARG=${1#--}
if [ "$ARG" = "bhr" -o "$ARG" = "beheer" ]
then
ENV=bhr
CONFDIR=./environments/aws_bhr/
elif [ "$ARG" = "prd" -o "$ARG" = "prod" ]
then
ENV=prd
CONFDIR=./environments/aws_prd/
elif [ "$ARG" = "acc" ]
then
ENV=acc
CONFDIR=./environments/aws_acc/
elif [ "$ARG" = "tst" -o "$ARG" = "test" ]
then
ENV=tst
CONFDIR=./environments/aws_tst/
else
echo "syntax: $0 <bhr|tst|acc|pord> [-r] <selector> <command>"
echo "Please specify an environment to deploy (bhr, prod, acc, test)"
exit 1
fi
shift
yes=0
if [ "$1" = "-y" ]
then
yes=1
shift
fi
root=
if [ "$1" = "-r" ]
then
root="--become --ask-become-pass"
shift
fi
if [ "$#" -lt 2 ]
then
echo "Please specify a host selector (i.e., 'all') and a command"
exit 1
fi
host=$1
cmd=$2
if [ "$yes" == "0" ]
then
echo -n "Will run '$cmd' on host '$ENV/$host'" >&2
if [ -n "$root" ]
then
echo -n " as root" >&2
fi
echo >&2
echo -n "Press enter to continue" >&2
read
echo
fi
ansible -v -i ${CONFDIR}/inventory $root "$host" -m command -a "$cmd"
exit 0