-
Notifications
You must be signed in to change notification settings - Fork 4
/
remote-env
executable file
·108 lines (94 loc) · 3.06 KB
/
remote-env
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
#!/usr/bin/env bash +a
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distrbuted under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
source .dev-profile
: ${SSH_KEY_FILE?"Please set the ssh key file to access the remote environment"}
: ${DEV_AMBARI_REPO_URL?"Please set the ambari repo base url"}
ansible-docker(){
eval "docker run --rm -it -v ~/prj/ambari:/ambari -v ~/prj/ambari-dev-env:/tmp -v $SSH_KEY_FILE:/tmp/ssh ansible/centos7-ansible ansible-playbook -i /tmp/ansible/hosts /tmp/ansible/dev-env.yml $1"
}
generate-inventory(){
echo "Generting inventory file ..."
while read -r LINE
do
IP=$(echo "$LINE" | awk '{print $1}')
echo "Processing ip: $IP"
if [ -z "$AMBARI_SERVER" ]
then
AMBARI_SERVER="$IP"
else
AMBARI_AGENTS="$AMBARI_AGENTS
$IP"
fi
done <"host_info"
cat <<EOF > ansible/hosts
[ambari-server]
$AMBARI_SERVER
[ambari-agent]
$AMBARI_AGENTS
[ambari-agent:vars]
ambari_server=$AMBARI_SERVER
EOF
}
main(){
if [ ! -f "ansible/hosts" ]; then
generate-inventory
fi
options=("Setup" "Clean" "Restart All" "Restart Server" "Stop Server" "Stop Agents" "Start Agents" "Restart agents" "dev-rpm-setup" "Quit")
select opt in "${options[@]}"
do
case $opt in
"Setup")
ansible-docker "--extra-vars '{ \"env_op\": \"setup\", \"base_url\": \"$DEV_AMBARI_REPO_URL\"}' -vvv"
eval $cmd
break
;;
"Clean")
ansible-docker "--extra-vars \"env_op=clean base_url=$DEV_AMBARI_REPO_URL\" -vvv"
break
;;
"Restart All")
ansible-docker "--extra-vars \"agent_op=restart,server_op=restart\" -vvv"
break
;;
"Restart Server")
ansible-docker "--extra-vars \"server_op=restart\" -vvv"
break
;;
"Stop Server")
ansible-docker "--extra-vars \"server_op=stop\" -vvv"
break
;;
"Stop Agents")
ansible-docker "--extra-vars \"agent_op=stop\" -vvv"
break
;;
"Start Agents")
ansible-docker "--extra-vars \"agent_op=start\" -vvv"
break
;;
"Restart Agents")
ansible-docker "--extra-vars \"agent_op=restart\" -vvv"
break
;;
"dev-rpm-setup")
ansible-docker "--extra-vars \"env_op=local-rpm\" -vvv"
break
;;
"Quit")
break
;;
*) echo invalid option;;
esac
done
}
main "$@"