-
Notifications
You must be signed in to change notification settings - Fork 10
/
pf9-express
executable file
·724 lines (631 loc) · 22.5 KB
/
pf9-express
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
#!/bin/bash
################################################################################
## Platform9 Assimilation Utility
## Copyright(c) 2018 Platform9 Systems, Inc.
################################################################################
# initialize variables
basedir=$(dirname $0)
oscli_version=pike
oscli_rc_file=${basedir}/pf9-openstack.rc
inventory=${basedir}/inventory/hosts
express_script=${basedir}/pf9-express.yml
deauth_script=${basedir}/pf9-deauth.yml
k8s_upgrade_script=${basedir}/pf9-k8s-upgrade.yml
k8s_only_playbook=${basedir}/pf9-k8s-express.yml
platform=""
target=""
log=/tmp/pf9-express.log
install_log="${basedir}/log/pf9-express.`date "+%Y-%m-%d_%H:%M:%S"`.log"
pf9_config=${basedir}/pf9-express.conf
pf9_config_tpl=${basedir}/lib/pf9-express.tpl
pf9_group_vars=${basedir}/group_vars/all.yml
pf9_custom_configFile=""
awx_repo_dir=/opt/awx
awx_repo=https://github.com/ansible/awx.git
awxcli_repo_dir=/opt/tower-cli
awxcli_repo=https://github.com/ansible/tower-cli.git
flag_setup=0
flag_prereqs=0
flag_ui=0
flag_oscli=0
flag_dbinit=0
flag_skip_prereqs=0
flag_awx_restart=0
flag_autoregister=0
flag_csvImport=0
flag_deauth=0
flag_k8s_upgrade=0
flag_pmk_only=0
verbosity=""
extra_vars=""
awx_pf9_user="pf9"
awx_pf9_password="Pl@tform9"
awx_pf9_email="[email protected]"
awx_db_export=awx-db-backup-v0.2.sql
tags=""
IFS_orig="${IFS}"
export PATH=/usr/local/bin:$PATH
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_COLLATE=C
export LC_CTYPE=en_US.UTF-8
# functions
usage() {
echo "Usage: $0 [Args] <target>"
echo -e "\nArgs (Optional):\n"
echo "-a|--autoRegister : auto-register host with management plane"
echo "-i|--installPrereqs : install pre-requisites and exit"
echo "-s|--setup : run setup and exit"
echo "-o|--oscli : install OpenStack CLI"
echo "-c|--config <configFile> : use custom configuration file"
echo "-e|--extra-vars <string> : ansible extra-vars <name=val,...>"
echo "-b|--bypassPrereqs : bypass pre-requisites"
echo "-d|--deauth : de-authorize host"
echo "-l|--log : Log output file. Assumes parent directory already exists."
echo "-u|--upgradeK8s : upgrade Kubernetes nodes"
echo "-v|--inventory <file> : use alternate inventory file for Ansible"
echo "-g|--debug : use extra ansible verbosity for debugging"
echo "-f|--csvFile <file> : import CSV file"
echo "-t|--tag <tag[,<tag>]> : available tags = [live-migration, image-import]"
echo -e "-h|--help : display this message\n"
if [ $# -eq 1 -a "${1}" == "-q" ]; then
:
else
exit 1
fi
}
csv_import() {
if [ ! -f ${csv_file} ]; then assert "CSV file not found"; fi
# Define templates
tmp_inventory=/tmp/pf9-hosts.tmp
tpl_global=${basedir}/lib/pf9-builder/template/hosts-global.tpl
tpl_hypervisors=${basedir}/lib/pf9-builder/template/hosts-hypervisors.tpl
tpl_glance=${basedir}/lib/pf9-builder/template/hosts-glance.tpl
tpl_cinder=${basedir}/lib/pf9-builder/template/hosts-cinder.tpl
tpl_bond_config=${basedir}/lib/pf9-builder/template/hosts-bond_config.tpl
# Initialize Inventory (from template)
if [ -r ${tmp_inventory} ]; then rm -f ${tmp_inventory}; fi
cat ${tpl_global} > ${tmp_inventory}
cat ${tpl_hypervisors} >> ${tmp_inventory}
# build hypervisors stanza
cnt=0; IFS=","
while read line; do
if [ ${cnt} -eq 0 ]; then ((cnt++)); continue; fi
lineArgs=(${line})
inv_entry="${lineArgs[0]} ansible_host=${lineArgs[3]} ansible_user=${lineArgs[1]} ansible_ssh_private_key_file=${lineArgs[2]}"
# check for dhcp
if [ "${lineArgs[4]}" == "TRUE" ]; then
inv_entry="${inv_entry} dhcp=on"
fi
# check for snat
if [ "${lineArgs[5]}" == "TRUE" ]; then
inv_entry="${inv_entry} snat=on"
fi
# update hypervisor inventory entry
echo ${inv_entry} >> ${tmp_inventory}
((cnt++))
done < ${csv_file}
# build glance stanza
cat ${tpl_glance} >> ${tmp_inventory}
cnt=0; IFS=","
while read line; do
if [ ${cnt} -eq 0 ]; then ((cnt++)); continue; fi
# add glance stanza
lineArgs=(${line})
if [ "${lineArgs[6]}" == "TRUE" ]; then
inv_entry="${lineArgs[0]}"
if [ "${lineArgs[7]}" == "TRUE" ]; then
inv_entry="${inv_entry} glance_public_endpoint=True"
fi
echo ${inv_entry} >> ${tmp_inventory}
fi
((cnt++))
done < ${csv_file}
# build cinder stanza
cat ${tpl_cinder} >> ${tmp_inventory}
# build bond-config stanza
cat ${tpl_bond_config} >> ${tmp_inventory}
cnt=0; IFS=","
while read line; do
if [ ${cnt} -eq 0 ]; then ((cnt++)); continue; fi
# add glance stanza
lineArgs=(${line})
interfaces=""
IFS="${IFS_orig}"
if [ -n "${lineArgs[8]}" ]; then
if [ -z "${interfaces}" ]; then
interfaces="\"${lineArgs[8]}\""
else
interfaces="${interfaces},\"${lineArgs[9]}\""
fi
fi
if [ -n "${lineArgs[9]}" ]; then
if [ -z "${interfaces}" ]; then
interfaces="\"${lineArgs[9]}\""
else
interfaces="${interfaces},\"${lineArgs[9]}\""
fi
fi
inv_entry="${lineArgs[0]} bond_members='[${interfaces}]'"
# add sub-interfaces
sub_interfaces=""
if [ -n "${lineArgs[10]}" ]; then
if [ -z "${sub_interfaces}" ]; then
sub_interfaces="{\"vlanid\":\"${lineArgs[10]}\",\"ip\":\"${lineArgs[11]}\",\"mask\":\"${lineArgs[12]}\"}"
else
sub_interfaces="${sub_interfaces},{\"vlanid\":\"${lineArgs[10]}\",\"ip\":\"${lineArgs[11]}\",\"mask\":\"${lineArgs[12]}\"}"
fi
inv_entry="${inv_entry} bond_sub_interfaces='[${sub_interfaces}]'"
fi
echo ${inv_entry} >> ${tmp_inventory}
IFS=","
((cnt++))
done < ${csv_file}
# backup existing inventory file (if exists)
if [ -r ${pf9_config} ]; then
ts=$(date +%s)
cp -f ${inventory} /tmp/hosts.${ts}
fi
# replace inventory file
cp -f ${tmp_inventory} ${inventory}
echo "Import Complete"
}
ansible_exec_path() {
ansible_exec=$(which ansible 2>/dev/null || true)
if [[ -e $(which ansible-3 2>/dev/null || true) ]]; then
ansible_exec=$(which ansible-3)
elif [[ -e $(which ansible3 2> /dev/null || true) ]]; then
ansible_exec=$(which ansible3)
fi
echo -n $ansible_exec
}
ansible_playbook_exec_path() {
ansible_playbook_exec=$(which ansible-playbook 2> /dev/null || true)
if [[ -e $(which ansible-playbook-3 2> /dev/null || true) ]]; then
ansible_playbook_exec=$(which ansible-playbook-3)
elif [[ -e $(which ansible-playbook3 2> /dev/null || true) ]]; then
ansible_playbook_exec=$(which ansible-playbook3)
fi
echo -n $ansible_playbook_exec
}
validate_platform() {
# check if running CentOS 7, Ubuntu 16.04, or Ubuntu 18.04
if [ -r /etc/centos-release ]; then
release=$(cat /etc/centos-release | cut -d ' ' -f 4)
if [[ ! "${release}" == 7.* ]]; then assert "unsupported CentOS release: ${release}"; fi
platform="centos"
host_os_info=$(cat /etc/centos-release)
elif [ -r /etc/lsb-release ]; then
release=$(cat /etc/lsb-release | grep ^DISTRIB_RELEASE= /etc/lsb-release | cut -d '=' -f2)
if [[ ! "${release}" == 16.04* ]] && [[ ! "${release}" == 18.04* ]] && [[ ! "${release}" == 20.04* ]] ; then assert "unsupported Ubuntu release: ${release}"; fi
platform="ubuntu"
ubuntu_release=$(cat /etc/lsb-release | grep ^DISTRIB_RELEASE | cut -d = -f2)
host_os_info="${platform} ${ubuntu_release}"
elif [ -r /etc/rocky-release ]; then
release=$(cat /etc/rocky-release | cut -d ' ' -f 4)
if [[ ! "${release}" == 9.* ]]; then assert "unsupported Rocky release: ${release}"; fi
platform="rocky"
host_os_info=$(cat /etc/rocky-release)
else
assert "unsupported platform"
fi
echo "Found release $release on platform $platform"
}
banner() {
echo "################################################################"
echo "# Platform9 Express Utility"
echo "################################################################"
}
restart_awx() {
echo "[ Restarting AWX ]"
# stop awx
for container in awx_task awx_web; do
echo "--> stopping ${container}"
sudo docker stop ${container} > /dev/null 2>&1
sudo docker stop ${container} > /dev/null 2>&1
done
# start awx
sleep 5
${basedir}/pf9-express -u
exit 0
}
nginx_init() {
# copy nginx.conf
sudo docker cp ${basedir}/lib/nginx.conf awx_web:/etc/nginx/nginx.conf
# restart nginx container
docker exec awx_web nginx -s reload
}
db_init() {
echo "[ Installing AWX Database ]"
# copy database export
echo "--> copying default database"
sudo docker cp ${basedir}/lib/${awx_db_export} postgres:/tmp
# stop awx
docker stop awx_web > /dev/null 2>&1
docker stop awx_task > /dev/null 2>&1
# drop awx database
echo "--> importing default database"
docker exec postgres bash -c "su - postgres -c 'psql -c \"drop database awx;\"'" > /dev/null 2>&1
# initialize awx database
docker exec postgres bash -c "su - postgres -c 'psql -c \"create database awx with template template0;\"'" > /dev/null 2>&1
# import awx database (exported using 'pg_dump awx > db.sql')
docker exec postgres bash -c "su - postgres -c 'psql -d awx -f /tmp/${awx_db_export};'" > /dev/null 2>&1
# start awx
echo "--> restarting AWX"
${basedir}/pf9-express -u > /dev/null 2>&1
}
install_awx() {
echo "[ Installing Web UI (Ansible AWX) ]"
echo "--> Installation Log: ${log}"
# check if docker is installed
docker -h > /dev/null 2>&1
if [ $? -ne 0 ]; then assert "Docker is not installed"; fi
# clone AWX repo
echo -n "--> validating awx repository: "
if [ -r ${awx_repo_dir} ]; then
echo "present"
else
echo "missing - cloning..."
sudo git clone ${awx_repo} ${awx_repo_dir} > ${log} 2>&1
if [ $? -ne 0 ]; then assert "failed to clone git repo: ${awx_repo}"; fi
fi
# Install Tower CLI
echo "--> installing tower-cli"
sudo pip3 install ansible-tower-cli > ${log} 2>&1
if [ $? -ne 0 ]; then assert "failed to pip3 install ansible-tower-cli"; fi
sudo /bin/cp -f ${basedir}/lib/tower_cli.cfg.tpl /root/.tower_cli.cfg
if [ $? -ne 0 ]; then assert "failed to copy lib/tower_cli.cfg.tpl"; fi
sudo chmod 0400 /root/.tower_cli.cfg
if [ $? -ne 0 ]; then assert "failed to set permissions on /root/.tower_cli.cfg"; fi
# Install AWX (Docker-based)
echo "--> installing awx (this will take a while - monitor log for status)"
(cd ${awx_repo_dir}/installer && sudo ansible-playbook -i inventory install.yml > ${log} 2>&1)
# Validate Tower CLI (timeout loop)
echo "--> waiting for awx to initialize"
TIMEOUT=600
start_time=`date +%s`
elapsedTime=0
while [ ${elapsedTime} -lt ${TIMEOUT} ]; do
sudo tower-cli version > /dev/null 2>&1
if [ $? -eq 0 ]; then break; fi
# update elapsed time
current_t=`date +%s`; elapsedTime=$((current_t - start_time))
sleep 5
done
# display timeout message
if [ ${elapsedTime} -ge ${TIMEOUT} ]; then
assert "*** TIMEOUT EXCEEDED *** waiting to connect to awx"
fi
}
# install_oscli <ctrl-hostname> <region> <tenant> <username> <password>
install_oscli() {
echo "[ Installing OpenStack CLI ]"
echo "--> Installation Log: ${log}"
if [ $# -ne 5 ]; then
echo "install_oscli(): missing arguments (expected 3; got $#)"
return 1
fi
# configure pf9-openstack.rc
echo "--> Building pf9-openstack.rc"
update_openstack_rc ${1} ${2} ${3} ${4} ${5}
# source rc file
source ${oscli_rc_file}
pip3 install python-openstackclient> ${log} 2>&1
echo "You may need to add /usr/local/bin to your \$PATH"
echo "export PATH=\$PATH:/usr/local/bin"
}
install_prereqs() {
echo "--> Installing Prerequisites"
# display log
echo "--> Installation Log: ${install_log}"
# install Ansible (and dependencies)
echo -n "--> Validating package dependencies: "
if [ "${platform}" == "centos" ]; then
for pkg in sshpass epel-release gcc python3-devel python3-pip jq; do
echo -n "${pkg} "
rpm -q ${pkg} > /dev/null 2>&1
if [ $? -ne 0 ]; then
sudo yum -y install ${pkg} > ${log} 2>&1
if [ $? -ne 0 ]; then
echo -e "\nERROR: failed to install ${pkg} - here's the last 10 lines of the log:\n"
tail -10 ${log}; exit 1
fi
fi
done
## upgrade pip
sudo pip3 install --upgrade pip > ${log} 2>&1
if [ $? -ne 0 ]; then
echo -e "\nERROR: failed to upgrade pip3 - here's the last 10 lines of the log:\n"
tail -10 ${log}; exit 1
fi
## install additional pip-based packages
for pkg in 'ansible==2.9.27 openstacksdk==0.62.0' docker-py pyopenssl; do
echo -n "${pkg} "
sudo pip3 install ${pkg} --ignore-installed > ${log} 2>&1
if [ $? -ne 0 ]; then
echo -e "\nERROR: failed to install ${pkg} - here's the last 10 lines of the log:\n"
tail -10 ${log}; exit 1
fi
done
echo
elif [ "${platform}" == "rocky" ]; then
for pkg in sshpass epel-release python3-devel python3-pip jq; do
echo -n "${pkg} "
dnf list installed | grep "^${pkg}\." > /dev/null 2>&1
if [ $? -ne 0 ]; then
sudo dnf -y install ${pkg} > ${log} 2>&1
if [ $? -ne 0 ]; then
echo -e "\nERROR: failed to install ${pkg} - here's the last 10 lines of the log:\n"
tail -10 ${log}; exit 1
fi
fi
done
## upgrade pip
sudo pip3 install --upgrade pip > ${log} 2>&1
if [ $? -ne 0 ]; then
echo -e "\nERROR: failed to upgrade pip3 - here's the last 10 lines of the log:\n"
tail -10 ${log}; exit 1
fi
## install additional pip-based packages
for pkg in 'ansible==2.9.27 openstacksdk==0.62.0' docker-py pyopenssl; do
echo -n "${pkg} "
sudo pip3 install ${pkg} --ignore-installed > ${log} 2>&1
if [ $? -ne 0 ]; then
echo -e "\nERROR: failed to install ${pkg} - here's the last 10 lines of the log:\n"
tail -10 ${log}; exit 1
fi
done
echo
elif [ "${platform}" == "ubuntu" ]; then
for pkg in sshpass jq python3 python3-dev python3-pip; do
echo -n "${pkg} "
dpkg-query -f '${binary:Package}\n' -W | grep ^${pkg}$ > /dev/null 2>&1
if [ $? -ne 0 ]; then
sudo apt-get -y install ${pkg} > ${log} 2>&1
if [ $? -ne 0 ]; then
echo -e "\nERROR: failed to install ${pkg} - here's the last 10 lines of the log:\n"
tail -10 ${log}; exit 1
fi
fi
done
## upgrade pip
sudo pip3 install --upgrade pip > ${log} 2>&1
if [ $? -ne 0 ]; then
echo -e "\nERROR: failed to upgrade pip3 - here's the last 10 lines of the log:\n"
tail -10 ${log}; exit 1
fi
## install additional pip-based packages
for pkg in 'ansible==2.9.27 openstacksdk==0.62.0' docker-py pyopenssl; do
echo -n "${pkg} "
sudo pip3 install ${pkg} --ignore-installed > ${log} 2>&1
if [ $? -ne 0 ]; then
echo -e "\nERROR: failed to install ${pkg} - here's the last 10 lines of the log:\n"
tail -10 ${log}; exit 1
fi
done
echo
fi
# create log directory
if [ ! -d /var/log/pf9 ]; then sudo mkdir -p /var/log/pf9; fi
}
display_warning() {
echo -e "\n################################################################################"
echo "#### WARNING : This action is destructive and cannot be undone"
echo -e "################################################################################\n"
getYN "Continue? "
}
################################################################################
## main
################################################################################
# include libraries
source ${basedir}/lib/config_util.sh
source ${basedir}/lib/utility.sh
## validate commandline arguments
if [ $# -lt 1 ]; then usage; fi
while [ $# -gt 0 ]; do
case ${1} in
-h|--help)
usage ;;
-s|--setup)
if [ ! -r ${pf9_config} ]; then init_config; fi
flag_setup=1
;;
-i|--installPrereqs)
flag_prereqs=1
;;
-o|--oscli)
flag_oscli=1
;;
-a|--autoRegister)
flag_autoregister=1
;;
-b|--bypassPrereqs)
flag_skip_prereqs=1
;;
-d|--deauth)
flag_deauth=1
;;
-g|--debug)
verbosity="-vvv"
;;
-l|--log)
if [ $# -lt 2 ]; then usage; fi
install_log=${2}
shift
;;
-u|--upgradeK8s)
flag_k8s_upgrade=1
;;
--pmk)
flag_pmk_only=1
;;
-f|--csvFile)
if [ $# -lt 2 ]; then usage; fi
flag_csvImport=1
csv_file=${2}
shift
;;
-t|--tag)
if [ $# -lt 2 ]; then usage; fi
tags=${2}
for tag in $(echo ${tags} | sed -e 's/,/ /g'); do
case ${tag} in
live-migration|image-import)
;;
*)
assert "invalid tag : '${tag}'"
esac
done
shift
;;
-c|--config)
if [ $# -lt 2 ]; then usage; fi
pf9_custom_configFile=${2}
shift
;;
-v|--inventory)
if [ $# -lt 2 ]; then usage; fi
inventory=${2}
shift
;;
-e|--extra-vars)
if [ $# -lt 2 ]; then usage; fi
extra_vars=${2}
shift
;;
*)
if [ $# -ne 1 ]; then usage; fi
target=${1}
;;
esac
shift
done
# validate platform (CentOS 7.4, Ubuntu 16.04, or Ubuntu 18.04)
validate_platform
## validate sudo priviledges
sudo bash <<< "exit 200"
if [ $? -ne 200 ]; then assert "you need sudo privilidges to run this script - please update /etc/sudoers"; fi
## enforce setup/custom-config mutual exclusivity
if [ ${flag_setup} -eq 1 -a -n "${pf9_custom_configFile}" ]; then assert "'-s' and '-c' are mutually exclusive"; fi
## run setup
if [ ${flag_setup} -eq 1 ]; then
run_setup
exit 0
fi
## use custom config (if specified on commandline)
if [ -n "${pf9_custom_configFile}" ]; then
pf9_config=${pf9_custom_configFile}
fi
# run setup if config file missing
if [ ! -r ${pf9_config} ]; then
init_config
run_setup
fi
## import CSV-based inventory file
if [ ${flag_csvImport} -eq 1 ]; then
csv_import ${csv_file}
fi
## build group_vars/all.yml
build_config --skip-inventory-check
# validate all config values are set
validate_config
## install prequisite packages
if [ ${flag_prereqs} -eq 1 ]; then
install_prereqs; echo
exit 0
fi
## restart awx
if [ ${flag_awx_restart} -eq 1 ]; then
restart_awx; echo
exit 0
fi
## install web ui
if [ ${flag_ui} -eq 1 -o ${flag_dbinit} -eq 1 ]; then
if [ ${flag_ui} -eq 1 ]; then
install_awx; echo
fi
## install awx database
if [ ${flag_dbinit} -eq 1 ]; then
db_init; echo
fi
exit 0
fi
## display banner
banner
# install prerequisite packages
if [ ${flag_skip_prereqs} -eq 0 ]; then install_prereqs; fi
## lookup configuration values from config file
du_url=$(grep ^du_url ${pf9_config} | cut -d \| -f2 | cut -d \/ -f3)
du_username=$(grep ^os_username ${pf9_config} | cut -d \| -f2)
du_password=$(grep ^os_password ${pf9_config} | cut -d \| -f2)
du_region=$(grep ^os_region ${pf9_config} | cut -d \| -f2)
du_tenant=$(grep ^os_tenant ${pf9_config} | cut -d \| -f2)
proxy_url=$(grep ^proxy_url ${pf9_config} | cut -d \| -f2)
## append proxy_url to extra_args
if [ "${proxy_url}" != "-" ]; then extra_vars="${extra_vars} proxy_url=${proxy_url}"; fi
## get region specific hostname
## Get Keystone Token
token=`curl -k -i -H "Content-Type: application/json" https://${du_url}/keystone/v3/auth/tokens?nocatalog \
-d "{ \"auth\": { \"identity\": { \"methods\": [\"password\"], \"password\": { \"user\": { \"name\": \"${du_username}\", \"domain\": {\"id\": \"default\"}, \"password\": \"${du_password}\" } } }, \"scope\": { \"project\": { \"name\": \"${du_tenant}\", \"domain\": {\"id\": \"default\"}}}}}" 2>/dev/null | grep -i ^X-Subject-Token | awk -F : '{print $2}' | sed -e 's/ //g' | sed -e 's/\r//g'`
## get region info
service_id=`curl -X GET -H "X-Auth-Token: ${token}" https://${du_url}/keystone/v3/services?type=regionInfo 2>/dev/null | grep -o '"id": "[a-z0-9 ]*' | cut -c 8-40`
region_url=`curl -X GET -H "X-Auth-Token: ${token}" https://${du_url}/keystone/v3/endpoints?service_id=${service_id} 2>/dev/null | jq --arg du_region "${du_region}" '.endpoints[] | select(.region_id==$du_region and .interface=="public")' | jq '.url' | awk '{print substr($0,2,length($0)-9)}' | cut -d '/' -f3`
## assign/validate ctrl_ip from config file and resolve IP for ctrl_hostname
ctrl_hostname=${region_url}
tmp_ip=$(ping -c 1 ${region_url} | grep PING | cut -d ' ' -f3)
ctrl_ip=${tmp_ip:1:((${#tmp_ip}-2))}
## install openstack cli
if [ ${flag_oscli} -eq 1 ]; then
install_oscli ${ctrl_hostname} ${du_region} ${du_tenant} ${du_username} ${du_password}
exit 0
fi
## validate target
if [ -z "${target}" ]; then usage; fi
## toggle auto-register flag
if [ ${flag_autoregister} -eq 1 ]; then
autoreg="on"
else
autoreg="off"
fi
## inform user of Ansible command being run
echo -e "\n[INFO]: Will use Ansible Playbook executable: $(ansible_playbook_exec_path)"
echo -e "\n[INFO]: Executing $(ansible_playbook_exec_path) ${express_script}"
## deauth host
if [ ${flag_deauth} -eq 1 ]; then
display_warning
if [ $? -eq 0 ]; then
extra_vars="${extra_vars} flag_deauth=1"
sudo $(ansible_playbook_exec_path) -i ${inventory} -l ${target} -e "skip_prereq=${flag_skip_prereqs} autoreg=${autoreg} du_fqdn=${ctrl_hostname} ctrl_ip=${ctrl_ip} du_username=${du_username} du_password=${du_password} ${extra_vars}" ${deauth_script} ${verbosity} 2>&1 | tee ${install_log}
echo -e "Log: ${install_log}\n"
fi
exit 0
fi
## Do stuff for PMK only
if [ ${flag_pmk_only} -eq 1 ]; then
# Fail if ansible errors out.
set -euo pipefail
extra_vars="${extra_vars} k8s_only=1"
echo -e "Log: ${install_log}\n"
sudo $(ansible_playbook_exec_path) -i ${inventory} -l ${target} -e "skip_prereq=${flag_skip_prereqs} autoreg=${autoreg} du_fqdn=${ctrl_hostname} ctrl_ip=${ctrl_ip} du_username=${du_username} du_password=${du_password} ${extra_vars}" ${k8s_only_playbook} ${verbosity} 2>&1 | tee ${install_log}
echo -e "Log: ${install_log}\n"
exit 0
fi
## upgrade K8s nodes
if [ ${flag_k8s_upgrade} -eq 1 ]; then
extra_vars="${extra_vars} flag_k8s_upgrade=1"
sudo $(ansible_playbook_exec_path) -i ${inventory} -l ${target} -e "skip_prereq=${flag_skip_prereqs} autoreg=${autoreg} du_fqdn=${ctrl_hostname} ctrl_ip=${ctrl_ip} du_username=${du_username} du_password=${du_password} ${extra_vars}" ${k8s_upgrade_script} ${verbosity} 2>&1 | tee ${install_log}
echo -e "Log: ${install_log}\n"
exit 0
fi
## manage tags
if [ -z "${tags}" ]; then
role_tags=""
else
role_tags="--tags ${tags}"
fi
## call pf9-express
sudo $(ansible_playbook_exec_path) -i ${inventory} -l ${target} ${role_tags} -e "skip_prereq=${flag_skip_prereqs} autoreg=${autoreg} du_fqdn=${ctrl_hostname} ctrl_ip=${ctrl_ip} du_username=${du_username} du_password=${du_password} ${extra_vars}" ${express_script} ${verbosity} 2>&1 | tee ${install_log}
## display log path
echo -e "Installation Log: ${install_log}\n"
## exit cleanly
exit 0