-
Notifications
You must be signed in to change notification settings - Fork 7
/
genansinv_extended.sh
executable file
·274 lines (243 loc) · 9.77 KB
/
genansinv_extended.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#!/bin/bash
TFSTATE_FILE=/tmp/tfshow.txt
terraform show terraform_extended/terraform.tfstate > $TFSTATE_FILE
if [ $# -lt 1 ]
then
echo "Error: script has less than 1 arguments, requires number_of_seeds_per_dc"
echo "-- usage: genansinv_extended.sh [<number_of_seeds_per_dc>]"
exit 1
fi
DSE_APPCLUSTER_NAME="DseCluster"
DSE_OPSCCLUSTER_NAME="OpscCluster"
dse_nodetype=()
public_ip=()
private_ip=()
# print message to a file (appending)
# $1 - message
# $2 - file to append
pmsg() {
echo "$1" >> $2
}
usage() {
echo "Error: [<number_of_seeds_per_dc>] accepts a postive number as the only input parameter"
echo "-- usage: genansinv_extended.sh [<number_of_seeds_per_dc>]"
}
# check if an input is a positive number
isnum() {
awk -v a="$1" 'BEGIN {print ((a == a + 0) && (a > 0)) }';
}
while IFS= read -r line
do
if [[ $line == *"aws_instance"* ]]; then
typestr="${line#*.}"
dse_nodetype+=("${typestr%?}")
fi
if [[ $line == *"private_ip ="* ]]; then
private_ip+=("${line#* = }")
fi
if [[ $line == *"public_ip ="* ]] && [[ $line =~ "\.[\d]+$" ]]; then
public_ip+=("${line#* = }")
fi
done < $TFSTATE_FILE
# Generate an IP list file
IPLIST_FILE="dse_ec2IpList"
publicIpCnt=${#public_ip[*]}
cat /dev/null > $IPLIST_FILE
for ((i=0; i<${#dse_nodetype[*]}; i++));
do
# in case there is no public IP available,
# we use private IP instead
if [[ $publicIpCnt == 0 ]]; then
public_ip[i]=${private_ip[i]}
fi
pmsg "${dse_nodetype[i]},${public_ip[i]},${private_ip[i]}" $IPLIST_FILE
done
# default number of seeds per DC is 1
# this can be changed from the only input parameter of this command
SEED_PER_DC=1
if [[ "$1" != "" ]]; then
res=`isnum "$1"`
if [[ "$res" != "1" ]] ; then
usage
exit
fi
SEED_PER_DC="$1"
fi
# Generate Ansible inventory file for multi-DC DSE cluster (no OpsCenter)
DSE_ANSINV_FILE="dse_ansHosts"
cat /dev/null > $DSE_ANSINV_FILE
pmsg "[dse:children]" $DSE_ANSINV_FILE
pmsg "dse_core" $DSE_ANSINV_FILE
pmsg "dse_search" $DSE_ANSINV_FILE
pmsg "dse_graph" $DSE_ANSINV_FILE
pmsg "dse_analytics" $DSE_ANSINV_FILE
pmsg "" $DSE_ANSINV_FILE
pmsg "[dse_core]" $DSE_ANSINV_FILE
seedmarked=0
for ((i=0; i<${#dse_nodetype[*]}; i++));
do
if [[ ${dse_nodetype[i]} == *"dse_core"* ]]; then
if [[ $seedmarked < $SEED_PER_DC ]]; then
if [ "${#public_ip[@]}" -eq 0 ]; then
pmsg "${private_ip[i]} private_ip=${private_ip[i]} private_dns=${private_dns[i]} seed=true dc=dse_core rack=RAC1 vnode=1 initial_token=" $DSE_ANSINV_FILE
seedmarked=$((seedmarked+1))
else
pmsg "${public_ip[i]} private_ip=${private_ip[i]} private_dns=${private_dns[i]} seed=true dc=dse_core rack=RAC1 vnode=1 initial_token=" $DSE_ANSINV_FILE
seedmarked=$((seedmarked+1))
fi
else
if [ "${#public_ip[@]}" -eq 0 ]; then
pmsg "${private_ip[i]} private_ip=${private_ip[i]} private_dns=${private_dns[i]} seed=false dc=dse_core rack=RAC1 vnode=1 initial_token=" $DSE_ANSINV_FILE
else
pmsg "${public_ip[i]} private_ip=${private_ip[i]} private_dns=${private_dns[i]} seed=false dc=dse_core rack=RAC1 vnode=1 initial_token=" $DSE_ANSINV_FILE
fi
fi
fi
done
pmsg "" $DSE_ANSINV_FILE
pmsg "[dse_search]" $DSE_ANSINV_FILE
seedmarked=0
for ((i=0; i<${#dse_nodetype[*]}; i++));
do
if [[ ${dse_nodetype[i]} == *"dse_search"* ]]; then
if [[ $seedmarked < $SEED_PER_DC ]]; then
if [ "${#public_ip[@]}" -eq 0 ]; then
pmsg "${private_ip[i]} private_ip=${private_ip[i]} private_dns=${private_dns[i]} seed=true dc=dse_search rack=RAC1 vnode=1 initial_token=" $DSE_ANSINV_FILE
seedmarked=$((seedmarked+1))
else
pmsg "${public_ip[i]} private_ip=${private_ip[i]} private_dns=${private_dns[i]} seed=true dc=dse_search rack=RAC1 vnode=1 initial_token=" $DSE_ANSINV_FILE
seedmarked=$((seedmarked+1))
fi
else
if [ "${#public_ip[@]}" -eq 0 ]; then
pmsg "${private_ip[i]} private_ip=${private_ip[i]} private_dns=${private_dns[i]} seed=false dc=dse_search rack=RAC1 vnode=1 initial_token=" $DSE_ANSINV_FILE
else
pmsg "${public_ip[i]} private_ip=${private_ip[i]} private_dns=${private_dns[i]} seed=false dc=dse_search rack=RAC1 vnode=1 initial_token=" $DSE_ANSINV_FILE
fi
fi
fi
done
pmsg "" $DSE_ANSINV_FILE
pmsg "[dse_graph]" $DSE_ANSINV_FILE
seedmarked=0
for ((i=0; i<${#dse_nodetype[*]}; i++));
do
if [[ ${dse_nodetype[i]} == *"dse_graph"* ]]; then
if [[ $seedmarked < $SEED_PER_DC ]]; then
if [ "${#public_ip[@]}" -eq 0 ]; then
pmsg "${private_ip[i]} private_ip=${private_ip[i]} private_dns=${private_dns[i]} seed=true dc=dse_graph rack=RAC1 vnode=1 initial_token=" $DSE_ANSINV_FILE
seedmarked=$((seedmarked+1))
else
pmsg "${public_ip[i]} private_ip=${private_ip[i]} private_dns=${private_dns[i]} seed=true dc=dse_graph rack=RAC1 vnode=1 initial_token=" $DSE_ANSINV_FILE
seedmarked=$((seedmarked+1))
fi
else
if [ "${#public_ip[@]}" -eq 0 ]; then
pmsg "${private_ip[i]} private_ip=${private_ip[i]} private_dns=${private_dns[i]} seed=false dc=dse_graph rack=RAC1 vnode=1 initial_token=" $DSE_ANSINV_FILE
else
pmsg "${public_ip[i]} private_ip=${private_ip[i]} private_dns=${private_dns[i]} seed=false dc=dse_graph rack=RAC1 vnode=1 initial_token=" $DSE_ANSINV_FILE
fi
fi
fi
done
pmsg "" $DSE_ANSINV_FILE
pmsg "[dse_analytics]" $DSE_ANSINV_FILE
seedmarked=0
for ((i=0; i<${#dse_nodetype[*]}; i++));
do
if [[ ${dse_nodetype[i]} == *"dse_analytics"* ]]; then
if [[ $seedmarked < $SEED_PER_DC ]]; then
if [ "${#public_ip[@]}" -eq 0 ]; then
pmsg "${private_ip[i]} private_ip=${private_ip[i]} private_dns=${private_dns[i]} seed=true dc=dse_analytics rack=RAC1 vnode=1 initial_token=" $DSE_ANSINV_FILE
seedmarked=$((seedmarked+1))
else
pmsg "${public_ip[i]} private_ip=${private_ip[i]} private_dns=${private_dns[i]} seed=true dc=dse_analytics rack=RAC1 vnode=1 initial_token=" $DSE_ANSINV_FILE
seedmarked=$((seedmarked+1))
fi
else
if [ "${#public_ip[@]}" -eq 0 ]; then
pmsg "${private_ip[i]} private_ip=${private_ip[i]} private_dns=${private_dns[i]} seed=false dc=dse_analytics rack=RAC1 vnode=1 initial_token=" $DSE_ANSINV_FILE
else
pmsg "${public_ip[i]} private_ip=${private_ip[i]} private_dns=${private_dns[i]} seed=false dc=dse_analytics rack=RAC1 vnode=1 initial_token=" $DSE_ANSINV_FILE
fi
fi
fi
done
pmsg "" $DSE_ANSINV_FILE
pmsg "[dse:vars]" $DSE_ANSINV_FILE
pmsg "cluster_name=$DSE_APPCLUSTER_NAME" $DSE_ANSINV_FILE
pmsg "" $DSE_ANSINV_FILE
pmsg "[dse_core:vars]" $DSE_ANSINV_FILE
pmsg "solr_enabled=0" $DSE_ANSINV_FILE
pmsg "spark_enabled=0" $DSE_ANSINV_FILE
pmsg "graph_enabled=0" $DSE_ANSINV_FILE
pmsg "auto_bootstrap=1" $DSE_ANSINV_FILE
pmsg "" $DSE_ANSINV_FILE
pmsg "[dse_search:vars]" $DSE_ANSINV_FILE
pmsg "solr_enabled=1" $DSE_ANSINV_FILE
pmsg "spark_enabled=0" $DSE_ANSINV_FILE
pmsg "graph_enabled=0" $DSE_ANSINV_FILE
pmsg "auto_bootstrap=1" $DSE_ANSINV_FILE
pmsg "" $DSE_ANSINV_FILE
pmsg "[dse_graph:vars]" $DSE_ANSINV_FILE
pmsg "solr_enabled=0" $DSE_ANSINV_FILE
pmsg "spark_enabled=0" $DSE_ANSINV_FILE
pmsg "graph_enabled=1" $DSE_ANSINV_FILE
pmsg "auto_bootstrap=1" $DSE_ANSINV_FILE
pmsg "" $DSE_ANSINV_FILE
pmsg "[dse_analytics:vars]" $DSE_ANSINV_FILE
pmsg "solr_enabled=0" $DSE_ANSINV_FILE
pmsg "spark_enabled=1" $DSE_ANSINV_FILE
pmsg "graph_enabled=0" $DSE_ANSINV_FILE
pmsg "auto_bootstrap=1" $DSE_ANSINV_FILE
pmsg "" $DSE_ANSINV_FILE
pmsg "" $DSE_ANSINV_FILE
pmsg "" $DSE_ANSINV_FILE
#if [ "${#selected_columns[@]}" -eq "${number_of_columns}" ]
pmsg "[opsc_dsecore]" $DSE_ANSINV_FILE
opscsrvmarked=0
seedmarked=0
opscSrvPrivateIP=''
for ((i=0; i<${#dse_nodetype[*]}; i++));
do
if [[ ${dse_nodetype[i]} == *"dse_opsc"* ]]; then
# only install OpsCenter server on one host
if [[ $opscsrvmarked == 0 ]]; then
if [ "${#public_ip[@]}" -eq 0 ]; then
opscSrvNodeStr="${private_ip[i]} private_ip=${private_ip[i]}"
else
opscSrvNodeStr="${public_ip[i]} private_ip=${private_ip[i]}"
fi
opscSrvPrivateIp="${private_ip[i]}"
opscsrvmarked=1
fi
if [[ $seedmarked < $SEED_PER_DC ]]; then
if [ "${#public_ip[@]}" -eq 0 ]; then
pmsg "${private_ip[i]} private_ip=${private_ip[i]} private_dns=${private_dns[i]} seed=true dc=DC1 rack=RAC1 vnode=1 initial_token=" $DSE_ANSINV_FILE
seedmarked=$((seedmarked+1))
else
pmsg "${public_ip[i]} private_ip=${private_ip[i]} private_dns=${private_dns[i]} seed=true dc=DC1 rack=RAC1 vnode=1 initial_token=" $DSE_ANSINV_FILE
seedmarked=$((seedmarked+1))
fi
else
if [ "${#public_ip[@]}" -eq 0 ]; then
pmsg "${private_ip[i]} private_ip=${private_ip[i]} private_dns=${private_dns[i]} seed=false dc=DC1 rack=RAC1 vnode=1 initial_token=" $DSE_ANSINV_FILE
else
pmsg "${public_ip[i]} private_ip=${private_ip[i]} private_dns=${private_dns[i]} seed=false dc=DC1 rack=RAC1 vnode=1 initial_token=" $DSE_ANSINV_FILE
fi
fi
fi
done
pmsg "" $DSE_ANSINV_FILE
pmsg "[opsc_dsecore:vars]" $DSE_ANSINV_FILE
pmsg "cluster_name=$DSE_OPSCCLUSTER_NAME" $DSE_ANSINV_FILE
pmsg "solr_enabled=0" $DSE_ANSINV_FILE
pmsg "spark_enabled=0" $DSE_ANSINV_FILE
pmsg "graph_enabled=0" $DSE_ANSINV_FILE
pmsg "auto_bootstrap=1" $DSE_ANSINV_FILE
pmsg "" $DSE_ANSINV_FILE
pmsg "[opsc_srv]" $DSE_ANSINV_FILE
pmsg "$opscSrvNodeStr" $DSE_ANSINV_FILE
pmsg "" $DSE_ANSINV_FILE
# Copy the generated ansible inventory file to the proper place
cp $DSE_ANSINV_FILE ./ansible/hosts