This post is a spin off from another post I’m working on related to ansible. I wanted to find a simple way to test ansible playbooks locally without any complication. A setup that would allow anyone to write ansible scripts for learning and run them locally without any fancy setup. There are other options like docker and vagrant but those require deeper knowledge to start.
Goal of this post are
- how can we have multiple virtual machines spined quickly within a local machine that can be used for anything without much complication.
- set up a passwordless SSH to the machine that multipass brings up.
Intro
Multipass is a tool by canonical, a company behind ubuntu. Using multipass you can bring up multiple ubuntu machines in your local area and access them to perform any actions.
Install
I’m on a Mac , so we can install it using brew. There are other binaries available for different operating systems here.
brew install multipass
lauch
Once installed you can just run multipass launch --name mytest1
this will spin a local ubuntu machine with the latest version and with a name mytest1. Once multipass brings the nodes up, you can watch status using multipass list
command , you can see the output below
login
You can login into the vm simply by using the multipass shell mytest1
. This will give you shell access, if you navigate around you will find its a plain ubuntu machine. We will soon see setting up the Password less ssh from your host machine to the multipass instance in a while.
Setup Password Less SSH
This steps actually works for any two remote machines.
-
On your host machine, copy the content of file
id_rsa.pub
from your.ssh
directory. You can use thecat /.ssh/id_rsa.pub
command to spit out the content to the terminal and then copy. -
Next you want to login in to the shell of of the ubuntu machine
mytest1
usingmultipass shell mytest1
command from host and paste the content copied from your host machine’s id_rsa.pub (in step1) in to ```/.ssh/authorize_keys file. -
To test the setup,
exit
from your ubuntu instance and while on your host machine, find the ip of the ubuntu instance by usingmultipass list
. -
Using the ip from step3, try
ssh ubuntu@ipv4addressofthemachine
. This works because you have copied the ssh keys required and also, the default user created by multipass instance is ubuntu.
Please explore the mulitpass
help command and you can do a lot more stuff with these tools. It supports cloud init as well that will allow you to define a template on the machine that multipass creates.