function multipassExecTask1
{
host=$1
echo $host
multipass exec $host -- sudo apt update -y
multipass exec $host -- sudo apt install ansible -y
multipass exec $host -- mkdir repo
multipass exec $host -- sudo addgroup --gid 8055 boss
multipass exec $host -- sudo adduser --system --shell /bin/bash --uid 805501 --gid 8055 aboss
multipass exec $host -- sudo adduser --system --shell /bin/bash --uid 905501 --gid 8055 adoss
multipass exec $host -- sudo usermod -aG sudo aboss
multipass exec $host -- sudo usermod -aG sudo aboss
multipass exec $host -- sudo passwd aboss
multipass exec $host -- sudo passwd adoss
multipass exec $host -- sudo sed -i "s/#PasswordAuthentication yes/PasswordAuthentication yes/" /etc/ssh/sshd_config
multipass exec $host -- sudo sed -i "s/#PubkeyAuthentication yes/PubkeyAuthentication yes/" /etc/ssh/sshd_config
multipass exec $host -- sudo sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin enabled/" /etc/ssh/sshd_config
multipass exec $host -- sudo ssh-keygen -t rsa -b 4096 -C "root"
# multipass exec $host -- sudo vim /etc/ssh/sshd_config
# multipass exec $host -- sudo passwd
# multipass exec $host -- sudo vim /root/.ssh/authorized_keys
# multipass restart $host
# multipass exec $host -- sudo vim /etc/default/kubelet
}
function multipassExecPostTask
{
host=$1
echo $host
id_rsa=`multipass exec $host -- sudo cat /root/.ssh/id_rsa.pub`
for chost in `cat hosts`
do
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-keyscan $host >> /root/.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
multipassExecTask1 $host
done
for host in `cat hosts`
do
multipassExecPostTask $host
done
for host in `cat hosts`
do
multipassExecSshVerify $host
done