-
Notifications
You must be signed in to change notification settings - Fork 0
/
03-configure-prod-vm.sh
67 lines (48 loc) · 1.91 KB
/
03-configure-prod-vm.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
#!/bin/bash
set -eux
scriptdir="$(dirname "$0")"
cd "$scriptdir"
doTheSsh() {
cmd=$1
echo $cmd
loop=0
max=10
code=9999
while [[ $code -gt 0 && $loop -le $max ]]
do
loop=$((loop + 1))
eval $cmd
code=$?
if [[ $code -gt 0 ]]
then
echo $code
echo "Wait 10 seconds, then retry"
sleep 10
fi
done
}
# ##################################################
echo "Start VM"
az vm start --subscription "$SUBSCRIPTION_ID" -g "$RG_NAME_VM_PROD" --name "$VM_PROD_NAME_1" --verbose
# ##################################################
echo "Get Production VM FQDN"
vmFqdnProd=$(echo "$(az network public-ip show --subscription ""$SUBSCRIPTION_ID"" -g ""$RG_NAME_VM_PROD"" -n ""$VM_PROD_NAME_1"" -o tsv --query 'dnsSettings.fqdn')" | sed "s/\r//")
# ##################################################
# Prepare start of below SSH commands
sshToVmCmdStart="ssh $DEPLOYMENT_SSH_USER_NAME@$vmFqdnProd -o StrictHostKeyChecking=off -i ~/.ssh/""$DEPLOYMENT_SSH_USER_KEY_NAME"
# ##################################################
# We will run the configuration script in remote-cmd.sh on deployed production VM next
remoteCmd=" \"bash -s\" < ./remote-cmd.sh"
sshToVmCmdFull="${sshToVmCmdStart} ${remoteCmd}"
doTheSsh "$sshToVmCmdFull"
# ##################################################
# Now we will run script to add a "real" admin user on deployed production VM
remoteCmd=" \"bash -s\" < ../vmadmin/create-user.sh \""$VM_ADMIN_SSH_USER_NAME"\" \""$VM_ADMIN_SSH_PUBLIC_KEY_INFIX"\""
sshToVmCmdFull="${sshToVmCmdStart} ${remoteCmd}"
doTheSsh "$sshToVmCmdFull"
# ##################################################
# Now we will run script to delete deployment user from deployed production VM
remoteCmd=" \"bash -s\" < ../vmadmin/delete-user.sh \""$DEPLOYMENT_SSH_USER_NAME"\""
sshToVmCmdFull="${sshToVmCmdStart} ${remoteCmd}"
doTheSsh "$sshToVmCmdFull"
# ##################################################