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])