-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd.sh
executable file
·1054 lines (948 loc) · 53 KB
/
cmd.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
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
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
#******************************************************************************
# Copyright 2020 Clark Hsu
#
# 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
# distributed 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.
#******************************************************************************
# How To
# https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#
# https://ansible-tips-and-tricks.readthedocs.io/en/latest/ansible/install/
# https://medium.com/@jackprice/low-risk-package-updates-with-ansible-and-vsphere-63f758c6b76a
# https://software.opensuse.org/download.html?project=systemsmanagement&package=ansible
# https://snapcraft.io/install/ansible-ryanjyoder/opensuse
# 'ansible all -m package -a 'name=* state=latest'`
#******************************************************************************
# Mark Off this section if use as lib
PROGRAM_NAME=$(basename "${0}")
AUTHOR=clark_hsu
VERSION=0.0.1
#******************************************************************************
echo -e "\n================================================================================\n"
#echo "Begin: $(basename "${0}")"
#set -e # Exit on error On
#set -x # Trace On
#******************************************************************************
# Load Configuration
echo -e "\n>>> Load Configuration...\n"
TOP_DIR=$(cd "$(dirname "${0}")" && pwd)
# shellcheck source=/dev/null
source "${HOME}/.mysecrets"
# shellcheck source=/dev/null
source "${HOME}/.myconfigs"
# shellcheck source=/dev/null
source "${HOME}/.mylib"
# shellcheck source=/dev/null
source "${HOME}/.myprojects"
# TOP_DIR=${CLOUD_MOUNT_PATH}
# TOP_DIR=${CLOUD_REPLICA_PATH}
# TOP_DIR=${DOCUMENTS_PATH}
# source "${TOP_DIR:?}/_common_lib.sh"
# source "${TOP_DIR:?}/setup.conf"
echo "${PASSWORD}" | sudo -S echo ""
if [ "${OPTION}" == "" ]; then
OPTION="${1}"
fi
#******************************************************************************
# Conditions Check and Init
# check_if_root_user
detect_package_system
set_alias_by_distribution # ${DISTRO}
PROJECT_TYPE=ansible_app # ansible_app bash_app bash_deployment_app bash_install_app bash_remote_deployment_app docker_app helm_app helm3_app minifest_app deployment_app terraform_app
#******************************************************************************
# Usage & Version
usage() {
cat <<EOF
Usage: ${0} -a <ACTION> [-o <OPTION>]
This script is to <DO ACTION>.
OPTIONS:
-h | --help Usage
-v | --version Version
-a | --action Action [create_project_skeleton | clean_project |
start_runtime | stop_runtime |
deploy_infrastructure | undeploy_infrastructure | install_infrastructure_requirements | uninstall_infrastructure_requirements |
install | update | upgrade | dist-upgrade | uninstall |
configure | remove_configurations |
enable | start | stop | disable |
deploy | undeploy |
show_infrastructure_status | show_k8s_status | show_app_status |
access_service | ssh_to_node |
status | get_version | lint]
EOF
exit 1
}
version() {
cat <<EOF
Program: ${PROGRAM_NAME}
Author: ${AUTHOR}
Version: ${VERSION}
EOF
exit 1
}
#******************************************************************************
# Command Line Parameters
while [[ "$#" -gt 0 ]]; do
OPTION="${1}"
case ${OPTION} in
-h | --help)
usage
;;
-v | --version)
version
;;
-a | --action)
ACTION="${2}"
shift
;;
-hd | --distro)
DISTRO="${2}"
shift
;;
-o | --os)
OS="${2}"
shift
;;
-a | --arch)
ARCH="${2}"
shift
;;
-p | --platform)
PLATFORM="${2}"
shift
;;
-pd | --platform_distro)
PLATFORM_DISTRO="${2}"
shift
;;
-m | --install_method)
INSTALL_METHOD="${2}"
shift
;;
-s | --source_directory)
SRC_DIR="${2}"
shift
;;
-d | --destination_directory)
DEST_DIR="${2}"
shift
;;
*)
# Others / Unknown Option
#usage
;;
esac
shift # past argument or value
done
if [ "${ACTION}" != "" ]; then
case ${ACTION} in
a | b | c) ;;
create_project_skeleton | clean_project) ;;
start_runtime | stop_runtime) ;;
deploy_infrastructure | undeploy_infrastructure | install_infrastructure_requirements | uninstall_infrastructure_requirements) ;;
install | update | upgrade | dist-upgrade | uninstall) ;;
configure | remove_configurations) ;;
enable | start | stop | disable) ;;
deploy | undeploy) ;;
show_infrastructure_status | show_k8s_status | show_app_status) ;;
access_service | ssh_to_node) ;;
status | get_version | lint) ;;
*)
usage
;;
esac
#else
# usage
fi
#******************************************************************************
# Functions
# function function_01() {
# if [ "$#" != "1" ]; then
# log_e "Usage: ${FUNCNAME[0]} <ARGS>"
# else
# log_m "${FUNCNAME[0]} ${*}"
# # cd "${TOP_DIR:?}" || exit 1
# fi
# }
function deploy_infrastructure() {
if [ "$#" != "3" ]; then
log_e "Usage: ${FUNCNAME[0]} <INFRASTRUCTURE_DEPLOYMENT_PROJECT_TOP_DIR> <PLATFORM> <PLATFORM_DISTRO>"
else
log_m "${FUNCNAME[0]} ${*}"
cd "${INFRASTRUCTURE_DEPLOYMENT_PROJECT_TOP_DIR}" || exit 1
# make install
# make deploy
# PLATFORM=libvirt
# OS=sles
./cmd.sh -a install ---platform ${PLATFORM} --platform_distro ${PLATFORM_DISTRO}
./cmd.sh -a deploy_infrastructure ---platform ${PLATFORM} --platform_distro ${PLATFORM_DISTRO}
fi
}
function undeploy_infrastructure() {
if [ "$#" != "3" ]; then
log_e "Usage: ${FUNCNAME[0]} <INFRASTRUCTURE_DEPLOYMENT_PROJECT_TOP_DIR> <PLATFORM> <PLATFORM_DISTRO>"
else
log_m "${FUNCNAME[0]} ${*}"
cd "${INFRASTRUCTURE_DEPLOYMENT_PROJECT_TOP_DIR}" || exit 1
# make undeploy
# make uninstall
# PLATFORM=libvirt
# OS=sles
./cmd.sh -a undeploy_infrastructure ---platform ${PLATFORM} --platform_distro ${PLATFORM_DISTRO}
./cmd.sh -a uninstall ---platform ${PLATFORM} --platform_distro ${PLATFORM_DISTRO}
./cmd.sh -a clean_project ---platform ${PLATFORM} --platform_distro ${PLATFORM_DISTRO}
fi
}
function set_packages_by_distribution() {
if [ "$#" != "0" ]; then
log_e "Usage: ${FUNCNAME[0]} <ARGS>"
else
log_m "${FUNCNAME[0]} ${*}"
# cd "${TOP_DIR:?}" || exit 1
if [ "${SRC_DIR}" == "" ]; then
# SRC_DIR=${HOME}/Documents/myProject
SRC_DIR=${HOME}/Documents/myProject/Template/helloworld_app
# SRC_DIR=${HOME}/Documents/myProject/Template/helloworld_template
fi
INSTALL_METHOD=pip # bin tar bz2 xz rar zip script snap rpm go npm pip docker
# https://github.com/${GITHUB_USER}/${GITHUB_PROJECT}/releases
PROJECT_BIN=ansible # ansible | ansible-ryanjyoder
PROJECT_BIN_RUN_PARAMETERS= #
SYSTEMD_SERVICE_NAME=${PROJECT_BIN} #
GITHUB_USER=ansible #
GITHUB_PROJECT=${PROJECT_BIN} #
# https://github.com/${GITHUB_USER}/${GITHUB_PROJECT}/releases
PACKAGE_VERSION=$(curl -s "https://api.github.com/repos/${GITHUB_USER}/${GITHUB_PROJECT}/releases/latest" | jq -r .tag_name)
echo ">>> Package: ${DISTRO}/${GITHUB_USER}/${GITHUB_PROJECT}/${PACKAGE_VERSION}/${PROJECT_BIN}-${OS}-${ARCH}"
case ${DISTRO} in
alpine)
# https://pkgs.alpinelinux.org/packages
PACKAGES_KEY_URL=
PACKAGES_REPO_NAME=
PACKAGES_REPO_URL=
PACKAGES="${PROJECT_BIN}"
REQUIRED_PACKAGES_KEY_URL=
REQUIRED_PACKAGES_REPO_NAME=
REQUIRED_PACKAGES_REPO_URL=
REQUIRED_PACKAGES=
PLUGIN_PACKAGES_KEY_URL=
PLUGIN_PACKAGES_REPO_NAME=
PLUGIN_PACKAGES_REPO_URL=
PLUGIN_PACKAGES=
;;
centos | fedora | rhel)
# https://pkgs.org/
# https://rpmfind.net/linux/RPM/index.html
PACKAGES_KEY_URL=
PACKAGES_REPO_NAME=
PACKAGES_REPO_URL=
PACKAGES="${PROJECT_BIN}"
REQUIRED_PACKAGES_KEY_URL=
REQUIRED_PACKAGES_REPO_NAME=
REQUIRED_PACKAGES_REPO_URL=
REQUIRED_PACKAGES=
PLUGIN_PACKAGES_KEY_URL=
PLUGIN_PACKAGES_REPO_NAME=
PLUGIN_PACKAGES_REPO_URL=
PLUGIN_PACKAGES=
;;
cirros)
PACKAGES_KEY_URL=
PACKAGES_REPO_NAME=
PACKAGES_REPO_URL=
PACKAGES="${PROJECT_BIN}"
REQUIRED_PACKAGES_KEY_URL=
REQUIRED_PACKAGES_REPO_NAME=
REQUIRED_PACKAGES_REPO_URL=
REQUIRED_PACKAGES=
PLUGIN_PACKAGES_KEY_URL=
PLUGIN_PACKAGES_REPO_NAME=
PLUGIN_PACKAGES_REPO_URL=
PLUGIN_PACKAGES=
;;
debian | raspios | ubuntu)
# https://www.debian.org/distrib/packages
# https://packages.ubuntu.com/
PACKAGES_KEY_URL=
PACKAGES_REPO_NAME=
PACKAGES_REPO_URL=
PACKAGES="${PROJECT_BIN}"
REQUIRED_PACKAGES_KEY_URL=
REQUIRED_PACKAGES_REPO_NAME=
REQUIRED_PACKAGES_REPO_URL=
REQUIRED_PACKAGES=
PLUGIN_PACKAGES_KEY_URL=
PLUGIN_PACKAGES_REPO_NAME=
PLUGIN_PACKAGES_REPO_URL=
PLUGIN_PACKAGES=
;;
opensuse-leap | opensuse-tumbleweed | sles)
# https://software.opensuse.org/find
PACKAGES_KEY_URL=
PACKAGES_REPO_NAME="systemsmanagement"
PACKAGES_REPO_URL="https://download.opensuse.org/repositories/systemsmanagement/SLE_15_SP1/systemsmanagement.repo"
PACKAGES="${PROJECT_BIN}"
REQUIRED_PACKAGES_KEY_URL=
REQUIRED_PACKAGES_REPO_NAME=
REQUIRED_PACKAGES_REPO_URL=
REQUIRED_PACKAGES=
PLUGIN_PACKAGES_KEY_URL=
PLUGIN_PACKAGES_REPO_NAME=
PLUGIN_PACKAGES_REPO_URL=
PLUGIN_PACKAGES=
;;
macosx)
# https://formulae.brew.sh/
# https://formulae.brew.sh/cask/
CASK=false
[[ ${CASK} == true ]] && set_alias_by_distribution
PACKAGES_KEY_URL=
PACKAGES_REPO_NAME=
PACKAGES_REPO_URL=
PACKAGES="${PROJECT_BIN}"
REQUIRED_PACKAGES_KEY_URL=
REQUIRED_PACKAGES_REPO_NAME=
REQUIRED_PACKAGES_REPO_URL=
REQUIRED_PACKAGES=
PLUGIN_PACKAGES_KEY_URL=
PLUGIN_PACKAGES_REPO_NAME=
PLUGIN_PACKAGES_REPO_URL=
PLUGIN_PACKAGES=
;;
microsoft)
PACKAGES_KEY_URL=
PACKAGES_REPO_NAME=
PACKAGES_REPO_URL=
PACKAGES="${PROJECT_BIN}"
REQUIRED_PACKAGES_KEY_URL=
REQUIRED_PACKAGES_REPO_NAME=
REQUIRED_PACKAGES_REPO_URL=
REQUIRED_PACKAGES=
PLUGIN_PACKAGES_KEY_URL=
PLUGIN_PACKAGES_REPO_NAME=
PLUGIN_PACKAGES_REPO_URL=
PLUGIN_PACKAGES=
;;
*) ;;
esac
PROJECT_BIN_URL= # "https://github.com/${GITHUB_USER}/${GITHUB_PROJECT}/releases/download/${PACKAGE_VERSION}/${PROJECT_BIN}_${OS}-${ARCH}"
PROJECT_TAR_URL= # "https://github.com/${GITHUB_USER}/${GITHUB_PROJECT}/releases/download/${PACKAGE_VERSION}/${PROJECT_BIN}-${PACKAGE_VERSION}-${OS}-${ARCH}.tar.gz"
PROJECT_BZ2_URL= # "https://github.com/${GITHUB_USER}/${GITHUB_PROJECT}/releases/download/${PACKAGE_VERSION}/${PROJECT_BIN}-${PACKAGE_VERSION}-${OS}-${ARCH}.bz2"
PROJECT_XZ_URL= # "https://github.com/${GITHUB_USER}/${GITHUB_PROJECT}/releases/download/${PACKAGE_VERSION}/${PROJECT_BIN}-${PACKAGE_VERSION}-${OS}-${ARCH}.xz"
PROJECT_RAR_URL= # "https://github.com/${GITHUB_USER}/${GITHUB_PROJECT}/releases/download/${PACKAGE_VERSION}/${PROJECT_BIN}-${PACKAGE_VERSION}-${OS}-${ARCH}.rar"
PROJECT_ZIP_URL= # "https://github.com/${GITHUB_USER}/${GITHUB_PROJECT}/releases/download/${PACKAGE_VERSION}/${PROJECT_BIN}-${PACKAGE_VERSION}-${OS}-${ARCH}.zip"
INSTALL_SCRIPT_URL= # "https://get.${GITHUB_PROJECT}.io" | "https://raw.githubusercontent.com/${GITHUB_USER}/${GITHUB_PROJECT}/master/bin/install.sh"
PKILL_SCRIPT_URL= # "https://get.${GITHUB_PROJECT}.io" | "https://raw.githubusercontent.com/${GITHUB_USER}/${GITHUB_PROJECT}/master/bin/pkillall.sh"
UNINSTALL_SCRIPT_URL= # "https://get.${GITHUB_PROJECT}.io" | "https://raw.githubusercontent.com/${GITHUB_USER}/${GITHUB_PROJECT}/master/bin/uninstall.sh"
INSTALL_SCRIPT_RUN_PARAMETERS=
UNINSTALL_SCRIPT_RUN_PARAMETERS=
# https://github.com/${GITHUB_USER}/${GITHUB_PROJECT}/releases
PROJECT_GO_URL=
PROJECT_GO_BIN=${PROJECT_BIN}
PROJECT_GO_BIN_RUN_PARAMETERS=
# https://github.com/${GITHUB_USER}/${GITHUB_PROJECT}/releases
PROJECT_NPM_BIN=${PROJECT_BIN}
PROJECT_NPM_BIN_RUN_PARAMETERS_RUN_PARAMETERS=
# https://github.com/${GITHUB_USER}/${GITHUB_PROJECT}/releases
PROJECT_PYTHON_PACKAGES="ansible ansible-base ansible-lint pytest pytest-cov pexpect PyYAML molecule molecule[docker] molecule[lint] paramiko argcomplete jinja2 netaddr"
PROJECT_PYTHON_BIN=${PROJECT_BIN}
PROJECT_PYTHON_BIN_RUN_PARAMETERS_RUN_PARAMETERS=
# https://github.com/${GITHUB_USER}/${GITHUB_PROJECT}/releases
DOCKER_REGISTRY=
DOCKER_USER=${GITHUB_USER}
DOCKER_PROJECT=${GITHUB_PROJECT}
TAG=latest # latest | latest-alpine | v0.0.1
EXTENSION= # a | b
fi
}
function set_deployment_settings() {
if [ "$#" != "0" ] && [ "$#" != "5" ]; then
log_e "Usage: ${FUNCNAME[0]} [<LOCATION> <PLATFORM> <PLATFORM_DISTRO> <RUNTIME> <SSH_USER> <SSH_GROUP>]"
else
log_m "${FUNCNAME[0]} ${*}"
# cd "${TOP_DIR:?}" || exit 1
if [ "$#" == "5" ]; then
LOCATION="${1}"
PLATFORM="${2}"
PLATFORM_DISTRO="${3}"
RUNTIME="${4}"
SSH_USER="${5}"
SSH_GROUP="${6}"
SSH_USER_PASSWORD= # linux
SSH_USER_PEM=
else
LOCATION=remote
PLATFORM=libvirt
PLATFORM_DISTRO=centos
RUNTIME=daemon
SSH_USER=centos
SSH_GROUP=remotes_env # remotes | remotes_env | remotes_mos
SSH_USER_PASSWORD= # linux
SSH_USER_PEM=
fi
echo ">>> SSH_USER/SSH_PASSWORD/SSH_USER_PEM: ${SSH_USER}/${SSH_PASSWORD}/${SSH_USER_PEM}"
echo ">>> Location/Platform/Distribution/Runtime: ${LOCATION}/${PLATFORM}/${PLATFORM_DISTRO}/${RUNTIME}"
INFRASTRUCTURE_DEPLOYMENT_PROJECT=terraform_env
INFRASTRUCTURE_DEPLOYMENT_PROJECT_TOP_DIR="${HOME}/Documents/myProject/Development/terraform/src/terraform/${INFRASTRUCTURE_DEPLOYMENT_PROJECT}" # ${TOP_DIR:?} | ${HOME}/Documents/myProject/Development/terraform/src/terraform/${INFRASTRUCTURE_DEPLOYMENT_PROJECT}
DEPLOYMENT_PLATFORM_DISTRO_TOP_DIR=${INFRASTRUCTURE_DEPLOYMENT_PROJECT_TOP_DIR}/providers/${PLATFORM}/${PLATFORM_DISTRO}
CONFIGURATION_MANAGEMENT_TOP_DIR=${TOP_DIR:?} # ${TOP_DIR:?}/inventories/${PLATFORM}/${PLATFORM_DISTRO}
REMOTE_CONFIGURATION_MANAGEMENT_TOP_DIR=/home/${SSH_USER}/inventories/${PLATFORM}/${PLATFORM_DISTRO}
echo ">>> INFRASTRUCTURE_DEPLOYMENT_PROJECT_TOP_DIR=${INFRASTRUCTURE_DEPLOYMENT_PROJECT_TOP_DIR}"
echo ">>> DEPLOYMENT_PLATFORM_DISTRO_TOP_DIR=${DEPLOYMENT_PLATFORM_DISTRO_TOP_DIR}"
echo ">>> CONFIGURATION_MANAGEMENT_TOP_DIR=${CONFIGURATION_MANAGEMENT_TOP_DIR}"
echo ">>> REMOTE_CONFIGURATION_MANAGEMENT_TOP_DIR=${REMOTE_CONFIGURATION_MANAGEMENT_TOP_DIR}"
STACK_NAME=env # env | mos | my-cluster
echo ">>> STACK_NAME=${STACK_NAME}"
NEW_ROLE=rke2
echo ">>> NEW_ROLE=${NEW_ROLE}"
# CRI= # crio docker containerd
# CNI= # calico cilium contiv-vpp flannel kube-router weave-net
# CSI= # daemon container kubernetes
# echo ">>> CRI=${CRI}"
# echo ">>> CNI=${CNI}"
# echo ">>> CSI=${CSI}"
RESET_CONFIG=false
RESET_SCRIPT=true
fi
}
function configure() {
if [ "$#" != "0" ]; then
log_e "Usage: ${FUNCNAME[0]} <ARGS>"
else
log_m "${FUNCNAME[0]} ${*}"
cd "${TOP_DIR:?}" || exit 1
case ${PLATFORM} in
aws | azure | gcp) ;;
libvirt) ;;
openstack) ;;
vmware | vsphere) ;;
*) ;;
esac
case ${DISTRO} in
alpine) ;;
centos | fedora | rhel | debian | raspios | ubuntu | opensuse-leap | opensuse-tumbleweed | sles) ;;
cirros) ;;
macosx) ;;
microsoft) ;;
*) ;;
esac
case ${PROJECT_TYPE} in
*) ;;
esac
case ${DEPLOYMENT_TYPE} in
*) ;;
esac
fi
}
function remove_configurations() {
if [ "$#" != "0" ]; then
log_e "Usage: ${FUNCNAME[0]} <ARGS>"
else
log_m "${FUNCNAME[0]} ${*}"
cd "${TOP_DIR:?}" || exit 1
case ${PLATFORM} in
aws | azure | gcp) ;;
libvirt) ;;
openstack) ;;
vmware | vsphere) ;;
*) ;;
esac
case ${DISTRO} in
alpine) ;;
centos | fedora | rhel | debian | raspios | ubuntu | opensuse-leap | opensuse-tumbleweed | sles) ;;
cirros) ;;
macosx) ;;
microsoft) ;;
*) ;;
esac
case ${PROJECT_TYPE} in
*) ;;
esac
case ${DEPLOYMENT_TYPE} in
*) ;;
esac
fi
}
function deploy() {
if [ "$#" != "0" ]; then
log_e "Usage: ${FUNCNAME[0]} <ARGS>"
else
log_m "${FUNCNAME[0]} ${*}"
cd "${TOP_DIR:?}" || exit 1
# ${NEW_ROLE}_install | ${NEW_ROLE}_uninstall | ${NEW_ROLE}_server_install | ${NEW_ROLE}_agent_install | ${NEW_ROLE}_plugins_install
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "${NEW_ROLE}_install" '{ "hosts": ["remotes"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "${NEW_ROLE}_install" '{ "hosts": ["remotes_mos"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "${NEW_ROLE}_install" '{ "hosts": ["remotes_env"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "${NEW_ROLE}_install" '{ "hosts": ["centos"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "${NEW_ROLE}_install" '{ "hosts": ["debian"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "${NEW_ROLE}_install" '{ "hosts": ["fedora"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "${NEW_ROLE}_install" '{ "hosts": ["rancher-k3os"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "${NEW_ROLE}_install" '{ "hosts": ["rancher-os"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "${NEW_ROLE}_install" '{ "hosts": ["opensuse-leap"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "${NEW_ROLE}_install" '{ "hosts": ["sles"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "${NEW_ROLE}_install" '{ "hosts": ["ubuntu"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "${NEW_ROLE}_install" '{ "hosts": ["centos-masters"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "${NEW_ROLE}_install" '{ "hosts": ["centos-workers"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "${NEW_ROLE}_install" '{ "hosts": ["ubuntu-masters"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "${NEW_ROLE}_install" '{ "hosts": ["ubuntu-workers"] }'
playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "${NEW_ROLE}_server_install" '{ "hosts": ["centos-masters"] }'
playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "${NEW_ROLE}_agent_install" '{ "hosts": ["centos-workers"] }'
fi
}
function undeploy() {
if [ "$#" != "0" ]; then
log_e "Usage: ${FUNCNAME[0]} <ARGS>"
else
log_m "${FUNCNAME[0]} ${*}"
cd "${TOP_DIR:?}" || exit 1
# ${NEW_ROLE}_install | ${NEW_ROLE}_uninstall | ${NEW_ROLE}_server_install | ${NEW_ROLE}_agent_install | ${NEW_ROLE}_plugins_install
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "${NEW_ROLE}_uninstall" '{ "hosts": ["remotes"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "${NEW_ROLE}_uninstall" '{ "hosts": ["remotes_mos"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "${NEW_ROLE}_uninstall" '{ "hosts": ["remotes_env"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "${NEW_ROLE}_uninstall" '{ "hosts": ["centos"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "${NEW_ROLE}_uninstall" '{ "hosts": ["debian"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "${NEW_ROLE}_uninstall" '{ "hosts": ["fedora"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "${NEW_ROLE}_uninstall" '{ "hosts": ["rancher-k3os"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "${NEW_ROLE}_uninstall" '{ "hosts": ["rancher-os"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "${NEW_ROLE}_uninstall" '{ "hosts": ["opensuse-leap"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "${NEW_ROLE}_uninstall" '{ "hosts": ["sles"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "${NEW_ROLE}_uninstall" '{ "hosts": ["ubuntu"] }'
playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "${NEW_ROLE}_uninstall" '{ "hosts": ["centos-masters"] }'
playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "${NEW_ROLE}_uninstall" '{ "hosts": ["centos-workers"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "${NEW_ROLE}_uninstall" '{ "hosts": ["ubuntu-masters"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "${NEW_ROLE}_uninstall" '{ "hosts": ["ubuntu-workers"] }'
fi
}
function access_service() {
if [ "$#" != "1" ]; then
log_e "Usage: ${FUNCNAME[0]} <ARGS>"
else
log_m "${FUNCNAME[0]} ${*}"
cd "${TOP_DIR:?}" || exit 1
fi
}
function ssh_to() {
if [ "$#" != "2" ]; then
log_e "Usage: ${FUNCNAME[0]} <DEPLOYMENT_PLATFORM_DISTRO_TOP_DIR> <INSTANCES_TYPE>"
else
log_m "${FUNCNAME[0]} ${*}"
# cd "${TOP_DIR:?}" || exit 1
clear
cd "${1}" || exit 1
SSH_USER=$(terraform output username)
if [ "${SSH_USER}" == "" ]; then
select_x_from_array "${DISTROS} rancher root ec2-user" "SSH_USER" SSH_USER # mos
fi
IP_INSTANCES=$(terraform output ${2} | cut -d "=" -f 2 | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | sed ':a;N;$!ba;s/\n/ /g' | tr -d '{' | tr -d '}' | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | tr -d '"')
select_x_from_array "${IP_INSTANCES}" "IP" IPssh_to_node
echo "${SSH_USER}" "${IP}"
if [ ${PRINT_CLOUD_INIT_LOG} == true ]; then
ssh_cmd "${SSH_USER}" "${IP}" "sudo cat /var/log/cloud-init.log"
# util.py[DEBUG]: The system is finally up, after 8.70 seconds
# main.py[DEBUG]: Ran 10 modules with 0 failures
# util.py[DEBUG]: Creating symbolic link from '/run/cloud-init/result.json' => '../../var/lib/cloud/data/result.json'
# util.py[DEBUG]: Reading from /proc/uptime (quiet=False)
# util.py[DEBUG]: Read 10 bytes from /proc/uptime
# util.py[DEBUG]: cloud-init mode 'modules' took 0.117 seconds (0.11)
# handlers.py[DEBUG]: finish: modules-final: SUCCESS: running modules for final
fi
ssh_cmd "${SSH_USER}" "${IP}"
fi
}
function ssh_command() {
if [ "$#" != "1" ] && [ "$#" != "2" ]; then
log_e "Usage: ${FUNCNAME[0]} <DEPLOYMENT_PLATFORM_DISTRO_TOP_DIR> [<INSTANCES_TYPE>]"
else
log_m "${FUNCNAME[0]} ${*}"
# cd "${TOP_DIR:?}" || exit 1
clear
cd "${1}" || exit 1
SSH_USER=$(terraform output username)
if [ "${SSH_USER}" == "" ]; then
select_x_from_array "${DISTROS} rancher root ec2-user" "SSH_USER" SSH_USER # "mos"
fi
if [ "$#" == "2" ]; then
IPS=$(terraform output ${2} | cut -d "=" -f 2 | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | sed ':a;N;$!ba;s/\n/ /g' | tr -d '{' | tr -d '}' | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | tr -d '"')
else
case ${INFRASTRUCTURE_DEPLOYMENT_PROJECT} in
terraform_env)
IP_ETCDS=$(terraform output ip_etcds | cut -d "=" -f 2 | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | sed ':a;N;$!ba;s/\n/ /g' | tr -d '{' | tr -d '}' | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | tr -d '"')
IP_STORAGES=$(terraform output ip_storages | cut -d "=" -f 2 | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | sed ':a;N;$!ba;s/\n/ /g' | tr -d '{' | tr -d '}' | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | tr -d '"')
IP_MASTERS=$(terraform output ip_masters | cut -d "=" -f 2 | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | sed ':a;N;$!ba;s/\n/ /g' | tr -d '{' | tr -d '}' | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | tr -d '"')
IP_WORKERS=$(terraform output ip_workers | cut -d "=" -f 2 | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | sed ':a;N;$!ba;s/\n/ /g' | tr -d '{' | tr -d '}' | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | tr -d '"')
IPS="${IP_ETCDS[*]} ${IP_STORAGES[*]} ${IP_MASTERS[*]} ${IP_WORKERS[*]}"
echo ">>> IPS: ${#IPS[*]} ${IPS}"
;;
terraform_mos)
IP_ALPINES=$(terraform output ip_alpines | cut -d "=" -f 2 | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | sed ':a;N;$!ba;s/\n/ /g' | tr -d '{' | tr -d '}' | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | tr -d '"')
IP_CENTOSS=$(terraform output ip_centoss | cut -d "=" -f 2 | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | sed ':a;N;$!ba;s/\n/ /g' | tr -d '{' | tr -d '}' | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | tr -d '"')
IP_CIRROSS=$(terraform output ip_cirross | cut -d "=" -f 2 | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | sed ':a;N;$!ba;s/\n/ /g' | tr -d '{' | tr -d '}' | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | tr -d '"')
IP_DEBIANS=$(terraform output ip_debians | cut -d "=" -f 2 | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | sed ':a;N;$!ba;s/\n/ /g' | tr -d '{' | tr -d '}' | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | tr -d '"')
IP_FEDORAS=$(terraform output ip_fedoras | cut -d "=" -f 2 | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | sed ':a;N;$!ba;s/\n/ /g' | tr -d '{' | tr -d '}' | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | tr -d '"')
IP_OPENSUSE_LEAPS=$(terraform output ip_opensuse_leaps | cut -d "=" -f 2 | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | sed ':a;N;$!ba;s/\n/ /g' | tr -d '{' | tr -d '}' | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | tr -d '"')
IP_RANCHER_K3OSS=$(terraform output ip_rancher_k3oss | cut -d "=" -f 2 | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | sed ':a;N;$!ba;s/\n/ /g' | tr -d '{' | tr -d '}' | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | tr -d '"')
IP_RANCHER_OSS=$(terraform output ip_rancher_oss | cut -d "=" -f 2 | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | sed ':a;N;$!ba;s/\n/ /g' | tr -d '{' | tr -d '}' | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | tr -d '"')
IP_RASPIOS=$(terraform output ip_raspioss | cut -d "=" -f 2 | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | sed ':a;N;$!ba;s/\n/ /g' | tr -d '{' | tr -d '}' | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | tr -d '"')
IP_SLESS=$(terraform output ip_sless | cut -d "=" -f 2 | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | sed ':a;N;$!ba;s/\n/ /g' | tr -d '{' | tr -d '}' | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | tr -d '"')
IP_UBUNTUS=$(terraform output ip_ubuntus | cut -d "=" -f 2 | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | sed ':a;N;$!ba;s/\n/ /g' | tr -d '{' | tr -d '}' | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | tr -d '"')
IPS="${IP_ALPINES} ${IP_CENTOSS[*]} ${IP_CIRROSS[*]} ${IP_DEBIANS[*]} ${IP_FEDORAS[*]} ${IP_OPENSUSE_LEAPS[*]} ${IP_RANCHER_K3OSS[*]} ${IP_RANCHER_OSS[*]} ${IP_RASPIOSS[*]} ${IP_SLESS[*]} ${IP_UBUNTUS[*]}"
echo ">>> IPS: ${#IPS[*]} ${IPS}"
;;
*) ;;
esac
fi
echo "${SSH_USER}" "${IPS}"
# local COMMANDS='uname -s; uname -m; echo; cat /etc/*-release | uniq -u; echo; hostnamectl'
# local COMMANDS='uname -s | tr A-Z a-z;'
# local COMMANDS='uname -m | sed s/x86_64/amd64/;'
# local COMMANDS='cat /etc/*-release | uniq -u | grep ^ID= | cut -d = -f 2 | sed s/\"//g;'
# local COMMANDS='command -v {apk,apt-get,brew,dnf,emerge,pacman,yum,zypper,xbps-install} 2>/dev/null;'
# local COMMANDS='command -v {apk,dpkg,pkgbuild,rpm} 2>/dev/null;'
# local COMMANDS='command -v {curl,wget} 2>/dev/null;'
# local COMMANDS='command -v {tar,unzip} 2>/dev/null;'
# local COMMANDS='OS=$(uname -s | tr A-Z a-z);ARCH=$(uname -m | sed s/x86_64/amd64/);DISTRO=$(cat /etc/*-release | uniq -u | grep ^ID= | cut -d = -f 2 | sed s/\"//g);PACKAGE_MANAGER=$(basename $(command -v {apk,apt-get,brew,dnf,emerge,pacman,yum,zypper,xbps-install} 2>/dev/null));PACKAGE_SYSTEM=$(basename $(command -v {apk,dpkg,pkgbuild,rpm} 2>/dev/null));echo "${OS} ${ARCH} ${DISTRO} ${PACKAGE_MANAGER} ${PACKAGE_SYSTEM}"'
local COMMANDS='. /etc/os-release && echo "${ID} ${VERSION_ID} ${VERSION}"'
for IP in ${IPS[*]}; do
# echo -e "\n>>> ${IP}...\n"
ssh_cmd "${SSH_USER}" "${IP}" "${COMMANDS}"
done
fi
}
#******************************************************************************
# Selection Parameters
if [ "${ACTION}" == "" ]; then
MAIN_OPTIONS="create_project_skeleton clean_project \
start_runtime stop_runtime \
deploy_infrastructure undeploy_infrastructure install_infrastructure_requirements uninstall_infrastructure_requirements \
install update upgrade uninstall \
configure remove_configurations \
start stop \
deploy undeploy \
show_infrastructure_status show_k8s_status show_app_status \
access_service ssh_to_node \
status get_version lint \
create_role \
ping facts ansible_distribution ansible_distribution_release ansible_os_family ansible_pkg_mgr \
ansible_distribution_version ansible_distribution_major_version ansible_update_packages \
playbook_helloworld playbook_hellorole \
is_packages_installed \
ssh_to ssh_to_command \
ssh_to_alpine ssh_to_centos ssh_to_cirros ssh_to_debian ssh_to_fedora ssh_to_opensuse_leap ssh_to_opensuse_tumbleweed ssh_to_rancher_k3os ssh_to_rancher_os ssh_to_raspios ssh_to_sles ssh_to_ubuntu"
select_x_from_array "${MAIN_OPTIONS}" "Action" ACTION # "a"
fi
# if [ "${XXX}" == "" ]; then
# # select_x_from_array "a b c" "XXX" XXX # "a"
# read_and_confirm "XXX MSG" XXX # "XXX set value"
# fi
set_packages_by_distribution
set_deployment_settings # "${LOCATION}" "${PLATFORM}" "${PLATFORM_DISTRO}" "${RUNTIME}" "${SSH_USER}"
if [ "${LOCATION}" == "remote" ]; then
cd "${DEPLOYMENT_PLATFORM_DISTRO_TOP_DIR}" || exit 1
case ${ACTION} in
create_project_skeleton | clean_project) ;;
start_runtime | stop_runtime) ;;
deploy_infrastructure | undeploy_infrastructure) ;;
install | update | upgrade | dist-upgrade | uninstall | enable | start | stop | disable) ;;
configure | remove_configurations) ;;
install_infrastructure_requirements | uninstall_infrastructure_requirements | deploy | undeploy | status | ssh_to_node)
case ${INFRASTRUCTURE_DEPLOYMENT_PROJECT} in
terraform_env)
IP_ETCDS=$(terraform output ip_etcds | cut -d "=" -f 2 | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | sed ':a;N;$!ba;s/\n/ /g' | tr -d '{' | tr -d '}' | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | tr -d '"')
IP_STORAGES=$(terraform output ip_storages | cut -d "=" -f 2 | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | sed ':a;N;$!ba;s/\n/ /g' | tr -d '{' | tr -d '}' | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | tr -d '"')
IP_MASTERS=$(terraform output ip_masters | cut -d "=" -f 2 | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | sed ':a;N;$!ba;s/\n/ /g' | tr -d '{' | tr -d '}' | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | tr -d '"')
IP_WORKERS=$(terraform output ip_workers | cut -d "=" -f 2 | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | sed ':a;N;$!ba;s/\n/ /g' | tr -d '{' | tr -d '}' | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | tr -d '"')
IPS="${IP_ETCDS[*]} ${IP_STORAGES[*]} ${IP_MASTERS[*]} ${IP_WORKERS[*]}"
echo ">>> IPS: ${#IPS[*]} ${IPS}"
;;
terraform_mos)
IP_ALPINES=$(terraform output ip_alpines | cut -d "=" -f 2 | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | sed ':a;N;$!ba;s/\n/ /g' | tr -d '{' | tr -d '}' | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | tr -d '"')
IP_CENTOSS=$(terraform output ip_centoss | cut -d "=" -f 2 | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | sed ':a;N;$!ba;s/\n/ /g' | tr -d '{' | tr -d '}' | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | tr -d '"')
IP_CIRROSS=$(terraform output ip_cirross | cut -d "=" -f 2 | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | sed ':a;N;$!ba;s/\n/ /g' | tr -d '{' | tr -d '}' | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | tr -d '"')
IP_DEBIANS=$(terraform output ip_debians | cut -d "=" -f 2 | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | sed ':a;N;$!ba;s/\n/ /g' | tr -d '{' | tr -d '}' | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | tr -d '"')
IP_FEDORAS=$(terraform output ip_fedoras | cut -d "=" -f 2 | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | sed ':a;N;$!ba;s/\n/ /g' | tr -d '{' | tr -d '}' | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | tr -d '"')
IP_OPENSUSE_LEAPS=$(terraform output ip_opensuse_leaps | cut -d "=" -f 2 | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | sed ':a;N;$!ba;s/\n/ /g' | tr -d '{' | tr -d '}' | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | tr -d '"')
IP_RANCHER_K3OSS=$(terraform output ip_rancher_k3oss | cut -d "=" -f 2 | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | sed ':a;N;$!ba;s/\n/ /g' | tr -d '{' | tr -d '}' | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | tr -d '"')
IP_RANCHER_OSS=$(terraform output ip_rancher_oss | cut -d "=" -f 2 | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | sed ':a;N;$!ba;s/\n/ /g' | tr -d '{' | tr -d '}' | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | tr -d '"')
IP_RASPIOS=$(terraform output ip_raspioss | cut -d "=" -f 2 | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | sed ':a;N;$!ba;s/\n/ /g' | tr -d '{' | tr -d '}' | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | tr -d '"')
IP_SLESS=$(terraform output ip_sless | cut -d "=" -f 2 | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | sed ':a;N;$!ba;s/\n/ /g' | tr -d '{' | tr -d '}' | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | tr -d '"')
IP_UBUNTUS=$(terraform output ip_ubuntus | cut -d "=" -f 2 | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | sed ':a;N;$!ba;s/\n/ /g' | tr -d '{' | tr -d '}' | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | tr -d '"')
IPS="${IP_ALPINES} ${IP_CENTOSS[*]} ${IP_CIRROSS[*]} ${IP_DEBIANS[*]} ${IP_FEDORAS[*]} ${IP_OPENSUSE_LEAPS[*]} ${IP_RANCHER_K3OSS[*]} ${IP_RANCHER_OSS[*]} ${IP_RASPIOSS[*]} ${IP_SLESS[*]} ${IP_UBUNTUS[*]}"
echo ">>> IPS: ${#IPS[*]} ${IPS}"
;;
*) ;;
esac
;;
show_infrastructure_status | show_k8s_status | show_app_status) ;;
access_service) ;;
get_version) ;;
*) ;;
esac
fi
# https://access.redhat.com/discussions/1173853
# sudo sed -i 's/#GSSAPIAuthentication no/GSSAPIAuthentication no/g' /etc/ssh/sshd_config
# sudo grep GSSAPIAuthentication /etc/ssh/sshd_config
# sudo sed -i 's/#UseDNS no/UseDNS no/g' /etc/ssh/sshd_config
# sudo sed -i 's/#UseDNS yes/UseDNS no/g' /etc/ssh/sshd_config
# sudo grep UseDNS /etc/ssh/sshd_config
# sudo systemctl restart sshd
#******************************************************************************
# Main Program
# update_datetime
# source_rc "${DISTRO}" "${PLATFORM}"
rm -rf "${HOME}/.ssh/known_hosts"
# https://www.ssh.com/ssh/agent
# ssh-agent bash
ssh-add "${HOME}/.ssh/id_rsa"
case ${ACTION} in
create_project_skeleton)
create_project_skeleton
;;
clean_project)
clean_project
;;
deploy_infrastructure)
deploy_infrastructure "${INFRASTRUCTURE_DEPLOYMENT_PROJECT_TOP_DIR}" "${PLATFORM}" "${PLATFORM_DISTRO}"
;;
undeploy_infrastructure)
undeploy_infrastructure "${INFRASTRUCTURE_DEPLOYMENT_PROJECT_TOP_DIR}" "${PLATFORM}" "${PLATFORM_DISTRO}"
;;
install_infrastructure_requirements)
install_infrastructure_requirements # "${PLATFORM}" "${PLATFORM_DISTRO}"
;;
uninstall_infrastructure_requirements)
uninstall_infrastructure_requirements # "${PLATFORM}" "${PLATFORM_DISTRO}"
;;
install)
# install_requirements # ${GITHUB_USER} ${GITHUB_PROJECT} ${PACKAGE_VERSION} ${OS} ${ARCH} ${PROJECT_BIN}
install # ${GITHUB_USER} ${GITHUB_PROJECT} ${PACKAGE_VERSION} ${OS} ${ARCH} ${PROJECT_BIN}
# install_plugins # ${GITHUB_USER} ${GITHUB_PROJECT} ${PACKAGE_VERSION} ${OS} ${ARCH} ${PROJECT_BIN}
;;
uninstall)
# uninstall_plugins # ${GITHUB_USER} ${GITHUB_PROJECT} ${PACKAGE_VERSION} ${OS} ${ARCH} ${PROJECT_BIN}
uninstall # ${GITHUB_USER} ${GITHUB_PROJECT} ${PACKAGE_VERSION} ${OS} ${ARCH} ${PROJECT_BIN}
# uninstall_requirements # ${GITHUB_USER} ${GITHUB_PROJECT} ${PACKAGE_VERSION} ${OS} ${ARCH} ${PROJECT_BIN}
;;
configure)
configure
;;
remove_configurations)
remove_configurations
;;
start)
start # ${PROJECT_BIN}
;;
stop)
stop # ${PROJECT_BIN}
;;
deploy)
deploy
# status
;;
undeploy)
undeploy
# status
;;
access_service)
access_service
;;
ssh_to_node)
select_x_from_array "${IP_MASTERS} ${IP_WORKERS}" "NODE_IP" IP
ssh_cmd "${SSH_USER}" "${IP}"
;;
status)
status
;;
get_version)
get_version # ${PROJECT_BIN}
;;
lint)
lint # ${PROJECT_BIN}
;;
create_role)
# NEW_ROLE="test" # ${NEW_ROLE} | ${NEW_ROLE}-server | ${NEW_ROLE}-agent
ROLES="firewalld"
for ROLE in ${ROLES[*]}; do
create_ansible_roles "${ROLE}"
create_ansible_role_tasks_for_main "${ROLE}"
create_ansible_role_tasks_darwin "${ROLE}"
create_ansible_role_tasks_for_debian "${ROLE}"
create_ansible_role_tasks_for_redhat "${ROLE}"
create_ansible_role_tasks_suse "${ROLE}"
create_ansible_role_vars_for_darwins "${ROLE}"
create_ansible_role_vars_for_redhats "${ROLE}"
create_ansible_role_vars_for_debians "${ROLE}"
create_ansible_role_vars_for_suses "${ROLE}"
done
;;
ping)
remote_module_action "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "ping"
;;
facts)
remote_module_action "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "ansible.builtin.setup"
;;
ansible_distribution)
# ansible all -m setup -a 'filter=ansible_distribution'
remote_module_action "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "setup" 'filter=ansible_distribution'
;;
ansible_distribution_release)
# ansible all -m setup -a 'filter=ansible_distribution_release'
remote_module_action "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "setup" 'filter=ansible_distribution_release'
;;
ansible_os_family)
# https://docs.ansible.com/ansible/latest/user_guide/playbooks_conditionals.html#ansible-facts-os-family
# ansible all -m setup -a 'filter=ansible_os_family'
remote_module_action "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "setup" 'filter=ansible_os_family'
;;
ansible_pkg_mgr)
# https://docs.ansible.com/ansible/latest/modules/list_of_packaging_modules.html
# ansible all -m setup -a 'filter=ansible_pkg_mgr'
remote_module_action "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "setup" 'filter=ansible_pkg_mgr'
;;
ansible_distribution_version)
# ansible all -m setup -a 'filter=ansible_distribution_version'
remote_module_action "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "setup" 'filter=ansible_distribution_version'
;;
ansible_distribution_major_version)
# ansible all -m setup -a 'filter=ansible_distribution_major_version'
remote_module_action "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "setup" 'filter=ansible_distribution_major_version'
;;
ansible_update_packages)
# ansible all -m package -a 'name=* state=latest'
remote_module_action "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "package" 'name=* state=latest'
# remote_module_action "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "apt" 'name=* state=latest'
# remote_module_action "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "yum" 'name=* state=latest'
# remote_module_action "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "zypper" 'name=* state=latest'
;;
playbook_helloworld)
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "hello_world" '{ "hosts": ["remotes"] }'
playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "hello_world" '{ "hosts": ["remotes_mos"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "hello_world" '{ "hosts": ["remotes_env"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "hello_world" '{ "hosts": ["centos"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "hello_world" '{ "hosts": ["debian"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "hello_world" '{ "hosts": ["fedora"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "hello_world" '{ "hosts": ["rancher-k3os"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "hello_world" '{ "hosts": ["rancher-os"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "hello_world" '{ "hosts": ["opensuse-leap"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "hello_world" '{ "hosts": ["sles"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "hello_world" '{ "hosts": ["ubuntu"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "hello_world" '{ "hosts": ["centos-masters"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "hello_world" '{ "hosts": ["centos-workers"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "hello_world" '{ "hosts": ["ubuntu-masters"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "hello_world" '{ "hosts": ["ubuntu-workers"] }'
;;
playbook_hellorole)
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "hello_role" '{ "hosts": ["remotes"] }'
playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "hello_role" '{ "hosts": ["remotes_mos"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "hello_role" '{ "hosts": ["remotes_env"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "hello_role" '{ "hosts": ["centos"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "hello_role" '{ "hosts": ["debian"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "hello_role" '{ "hosts": ["fedora"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "hello_role" '{ "hosts": ["rancher-k3os"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "hello_role" '{ "hosts": ["rancher-os"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "hello_role" '{ "hosts": ["opensuse-leap"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "hello_role" '{ "hosts": ["sles"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "hello_role" '{ "hosts": ["ubuntu"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "hello_role" '{ "hosts": ["centos-masters"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "hello_role" '{ "hosts": ["centos-workers"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "hello_role" '{ "hosts": ["ubuntu-masters"] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "hello_role" '{ "hosts": ["ubuntu-workers"] }'
;;
is_packages_installed)
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "is_packages_installed" '{ "hosts": ["remotes"], "pkgs": [ "foo", "bash-completion", "zip", "openssl", "python", "docker" ] }'
playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "is_packages_installed" '{ "hosts": ["remotes_mos"], "pkgs": [ "foo", "bash-completion", "zip", "openssl", "python", "docker" ] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "is_packages_installed" '{ "hosts": ["remotes_env"], "pkgs": [ "foo", "bash-completion", "zip", "openssl", "python", "docker" ] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "is_packages_installed" '{ "hosts": ["centos"], "pkgs": [ "foo", "bash-completion", "zip", "openssl", "python", "docker" ] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "is_packages_installed" '{ "hosts": ["debian"], "pkgs": [ "foo", "bash-completion", "zip", "openssl", "python", "docker" ] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "is_packages_installed" '{ "hosts": ["fedora"], "pkgs": [ "foo", "bash-completion", "zip", "openssl", "python", "docker" ] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "is_packages_installed" '{ "hosts": ["rancher-k3os"], "pkgs": [ "foo", "bash-completion", "zip", "openssl", "python", "docker" ] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "is_packages_installed" '{ "hosts": ["rancher-os"], "pkgs": [ "foo", "bash-completion", "zip", "openssl", "python", "docker" ] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "is_packages_installed" '{ "hosts": ["opensuse-leap"], "pkgs": [ "foo", "bash-completion", "zip", "openssl", "python", "docker" ] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "is_packages_installed" '{ "hosts": ["sles"], "pkgs": [ "foo", "bash-completion", "zip", "openssl", "python", "docker" ] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "is_packages_installed" '{ "hosts": ["ubuntu"], "pkgs": [ "foo", "bash-completion", "zip", "openssl", "python", "docker" ] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "is_packages_installed" '{ "hosts": ["centos-masters"], "pkgs": [ "foo", "bash-completion", "zip", "openssl", "python", "docker" ] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "is_packages_installed" '{ "hosts": ["centos-workers"], "pkgs": [ "foo", "bash-completion", "zip", "openssl", "python", "docker" ] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "is_packages_installed" '{ "hosts": ["ubuntu-masters"], "pkgs": [ "foo", "bash-completion", "zip", "openssl", "python", "docker" ] }'
# playbook "${PLATFORM}" "${SSH_USER}" "${SSH_GROUP}" "${SSH_PASSWORD}" "is_packages_installed" '{ "hosts": ["ubuntu-workers"], "pkgs": [ "foo", "bash-completion", "zip", "openssl", "python", "docker" ] }'
;;
ssh_to)
ssh_to "${DEPLOYMENT_PLATFORM_DISTRO_TOP_DIR}" # "ip_instances"
;;
ssh_command)
ssh_command "${DEPLOYMENT_PLATFORM_DISTRO_TOP_DIR}" # "ip_instances"
;;
ssh_to_lb)
ssh_to "${DEPLOYMENT_PLATFORM_DISTRO_TOP_DIR}" "ip_load_balancer"
;;
ssh_to_etcd)
ssh_to "${DEPLOYMENT_PLATFORM_DISTRO_TOP_DIR}" "ip_etcds"
# ssh_to "${DEPLOYMENT_PLATFORM_DISTRO_TOP_DIR}" "etcds_public_ip"
;;
ssh_to_storage)
ssh_to "${DEPLOYMENT_PLATFORM_DISTRO_TOP_DIR}" "ip_storages"
# ssh_to "${DEPLOYMENT_PLATFORM_DISTRO_TOP_DIR}" "storages_public_ip"
;;
ssh_to_master)
ssh_to "${DEPLOYMENT_PLATFORM_DISTRO_TOP_DIR}" "ip_masters"
# ssh_to "${DEPLOYMENT_PLATFORM_DISTRO_TOP_DIR}" "masters_public_ip"
;;
ssh_to_worker)
ssh_to "${DEPLOYMENT_PLATFORM_DISTRO_TOP_DIR}" "ip_workers"
# ssh_to "${DEPLOYMENT_PLATFORM_DISTRO_TOP_DIR}" "workers_public_ip"