Skip to content

Commit 734a517

Browse files
authored
Added verbose mode (#14)
* Added verbose mode * Removed --verbose
1 parent a8cada0 commit 734a517

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

ansible/mykube

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ options_display()
4141
echo "--no-console-deployment Disable console deployment."
4242
echo "--destroy Destroy existing vms"
4343
echo "--connect Connect to vm"
44+
echo "-v Verbose mode"
4445
echo "--help|-h Print this Help."
4546
}
4647

@@ -51,7 +52,7 @@ display_help()
5152
echo
5253
echo "MyKube is a new easy-to-use tool for creating your own virtual machine with k8s installed only by one click."
5354
echo
54-
echo "Syntax: ./start [-h|--help|--no-console-deployment|--destroy|--connect]"
55+
echo "Syntax: ./start [-h|--help|-v|--no-console-deployment|--destroy|--connect]"
5556
echo
5657
options_display
5758
}
@@ -94,11 +95,21 @@ loading_bar()
9495
sleep 0.15
9596
done
9697
done
97-
echo -n ""
98+
}
99+
100+
# Verobse function
101+
redirect_cmd() {
102+
# write your test however you want; this just tests if SILENT is non-empty
103+
if [ -z "$VERBOSE" ]; then
104+
"$@" &>/dev/null & PID=$!
105+
else
106+
"$@" & PID=$!
107+
fi
108+
loading_bar "$PID"
98109
}
99110

100111
# Options
101-
OPTIONS=$(getopt -o h --long help,connect,destroy,no-console-deploymentg -- "$@")
112+
OPTIONS=$(getopt -o h,v --long help,connect,destroy,no-console-deploymentg -- "$@")
102113

103114
VALID_ARGUMENTS=$?
104115
if [ "$VALID_ARGUMENTS" != "0" ]; then
@@ -111,6 +122,9 @@ while true; do
111122
-h | --help ) # Display help
112123
display_help
113124
exit 0;;
125+
-v ) # Verbose mode
126+
VERBOSE="true"
127+
shift;;
114128
--connect ) # Connect to vm
115129
connect_to_vm
116130
exit 0;;
@@ -190,7 +204,7 @@ else
190204
fi
191205

192206
echo -e "\nStart deploying the new vm..."
193-
virt-install -n "$VM_NAME" \
207+
redirect_cmd virt-install -n "$VM_NAME" \
194208
--description "my test $OS_ISO_SHORT_NAME vm" \
195209
--os-variant="$VM_OS_VARIANT" --ram="$VM_MEMORY" \
196210
--vcpus="$VM_VCPUS" \
@@ -200,12 +214,9 @@ virt-install -n "$VM_NAME" \
200214
--initrd-inject=$MYKUBE_DIR/ks.cfg \
201215
--extra-args='inst.ks=file:/ks.cfg console=tty0 console=ttyS0,115200n8' \
202216
--noautoconsole \
203-
--wait=-1 \
204-
--quiet & PID=$!
217+
--wait=-1
205218

206-
loading_bar "$PID"
207-
208-
echo -ne "VM $CREATED_GREEN"
219+
echo -e "VM $CREATED_GREEN"
209220

210221
# Waiting for IP address
211222
echo -e "\nWait for IP address to get assigned..."
@@ -238,12 +249,11 @@ echo -e "\nInstall k8s module for ansible"
238249
ansible-galaxy collection install kubernetes.core &> /dev/null
239250

240251
echo -e "\nRun ansible-playbook for deploying k8s..."
241-
ANSIBLE_HOST_KEY_CHECKING=false ansible-playbook "$MYKUBE_DIR/ansible/install-k8.yaml" -b \
252+
export ANSIBLE_HOST_KEY_CHECKING=false
253+
redirect_cmd ansible-playbook "$MYKUBE_DIR/ansible/install-k8.yaml" -b \
242254
-e "ansible_password=qwe123" \
243255
-i "$VM_IP_ADDRESS", \
244-
-e "$ANSIBLE_EXTRA_VARS" &> /dev/null & PID=$!
245-
246-
loading_bar "$PID"
256+
-e "$ANSIBLE_EXTRA_VARS"
247257

248258
display_login
249259

0 commit comments

Comments
 (0)