diff --git a/scripts/createVm.sh b/scripts/createVm.sh index a63947c..1e643a1 100644 --- a/scripts/createVm.sh +++ b/scripts/createVm.sh @@ -1,4 +1,4 @@ - +ENV=pac REGION=us HOSTMACHINE=mc02 VIRTUALMACHINE=mp @@ -7,6 +7,7 @@ NETWORK=en0 APP=kubeadm currentHost=`hostname` +CPU=2 function findEthEthernet { @@ -44,7 +45,7 @@ then HOSTMACHINE="mc01" fi - HOSTNAME_PREFIX="$REGION-$HOSTMACHINE-$VIRTUALMACHINE-`osVersion $OS $OSVERSION`-$NETWORK-$APP" + HOSTNAME_PREFIX="$REGION-$HOSTMACHINE-$ENV-$VIRTUALMACHINE-`osVersion $OS $OSVERSION`-$NETWORK-$APP" if [ "$action" == "create" ] then echo "create" @@ -55,10 +56,10 @@ echo $SEQ HOSTNAME="$HOSTNAME_PREFIX-$SEQ" - mkdir ~/data/$HOSTNAME + mkdir -p ~/data/$HOSTNAME if [ "$action" == "create" ] then - multipass launch $OSVERSION --name $HOSTNAME --memory 8G --disk 50G --cpus 8 --network en0 --mount ~/data/$HOSTNAME:/data/ + multipass launch $OSVERSION --name $HOSTNAME --memory 4G --disk 50G --cpus $CPU --network en0 --mount ~/data/$HOSTNAME:/data/ else multipass delete $HOSTNAME --purge diff --git a/scripts/hosts b/scripts/hosts index 6df1ece..bfc27d6 100644 --- a/scripts/hosts +++ b/scripts/hosts @@ -1,4 +1,4 @@ -us-mc02-mp-ub2204-en0-kubeadm-0 -us-mc02-mp-ub2204-en0-kubeadm-1 -us-mc02-mp-ub2204-en0-kubeadm-2 -us-mc02-mp-ub2204-en0-kubeadm-3 +us-mc02-pac-mp-ub2204-en0-kubeadm-0 +us-mc02-pac-mp-ub2204-en0-kubeadm-1 +us-mc02-pac-mp-ub2204-en0-kubeadm-2 +us-mc02-pac-mp-ub2204-en0-kubeadm-3 diff --git a/scripts/multipassInstallPreRequired.py b/scripts/multipassInstallPreRequired.py new file mode 100644 index 0000000..8055ca5 --- /dev/null +++ b/scripts/multipassInstallPreRequired.py @@ -0,0 +1,42 @@ +import subprocess + +def multipassExec(host, command): + command="multipass exec %s -- %s" % (host, command) + commandArr=command.split(" ") + result = subprocess.run(commandArr, capture_output=True, text=True) + # Print the output of the command + print(result.stdout) + +def multipassExecTask1(host): + multipassExec( host , "sudo apt update -y "); + multipassExec( host , "sudo apt install ansible -y ") + multipassExec( host , "mkdir repo") + multipassExec( host , "sudo addgroup --gid 8055 boss") + multipassExec( host , "sudo adduser --system --shell /bin/bash --uid 805501 --gid 8055 aboss") + multipassExec( host , "sudo adduser --system --shell /bin/bash --uid 905501 --gid 8055 adoss") + multipassExec( host , "sudo usermod -aG sudo aboss") + multipassExec( host , "sudo usermod -aG sudo aboss") + multipassExec( host , "sudo passwd aboss") + multipassExec( host , "sudo passwd adoss ") + multipassExec( host , 'sudo sed -i "s/#PasswordAuthentication yes/PasswordAuthentication yes/" /etc/ssh/sshd_config') + multipassExec( host , 'sudo sed -i "s/#PubkeyAuthentication yes/PubkeyAuthentication yes/" /etc/ssh/sshd_config') + multipassExec( host , 'sudo sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin enabled/" /etc/ssh/sshd_config') + multipassExec( host , 'sudo ssh-keygen -t rsa -b 4096 -C "root"') + +def multipassExecPostTask(host): + f = open("hosts", "r") + for chost in f: + print(chost) + multipassExec(chost ,"sudo cat /root/.ssh/id_rsa.pub\"") + multipassExec( host , "sudo sh -c \"echo '$id_rsa'>> /root/.ssh/authorized_keys\"") + f.close() + + +#for host in `cat hosts` +#do +# multipassExecTask1 $host +#done +f = open("hosts", "r") +for chost in f: + print(chost) + multipassExecTask1(chost[:-1]) diff --git a/scripts/multipassInstallPreRequired.sh b/scripts/multipassInstallPreRequired.sh index ad33712..d6be472 100644 --- a/scripts/multipassInstallPreRequired.sh +++ b/scripts/multipassInstallPreRequired.sh @@ -29,13 +29,28 @@ { host=$1 echo $host + id_rsa=`multipass exec $host -- sudo cat /root/.ssh/id_rsa.pub` for chost in `cat hosts` do - id_rsa=`multipass exec $chost -- sudo cat /root/.ssh/id_rsa.pub` - multipass exec $host -- sudo sh -c "echo '$id_rsa'>> /root/.ssh/authorized_keys" + echo $chost + multipass exec $chost -- sudo sh -c "echo '$id_rsa'>> /root/.ssh/authorized_keys" + echo "sleeping for 1 seconds copy from $host to $chost " + sleep 1 done } +function multipassExecSshVerify +{ + host=$1 + echo $host + for chost in `cat hosts` + do + echo $chost + multipass exec $chost -- sudo sh -c "ssh ssh-keyscan $host >> $HOME/.ssh/known_hosts" + #multipass exec $chost -- sudo ssh $host + #ssh-keyscan us-mc02-pac-mp-ub2204-en0-kubeadm-2 >> $HOME/.ssh/known_hosts + done +} for host in `cat hosts` do @@ -45,3 +60,7 @@ do multipassExecPostTask $host done +for host in `cat hosts` +do + multipassExecSshVerify $host +done