Sep 28, 2022

My Third Try on Multipass

After a few rounds of testing, you will find yourself repeating a lot of similar actions whenever creating an instance. For example:

  • creating new user
  • adding ssh public key
  • install Python, htop, Nodejs.....

YES, we can pre-configure all the actions every time a new instance is created. This is done via cloud-init.


First, create a YAML file called "cloud_init.yaml" with the following content.

users:
  - default
  - name: xx
    groups: sudo
    shell: /bin/bash
    sudo: ['ALL=(ALL) NOPASSWD:ALL']
    ssh_authorized_keys:
      - ssh-rsa <rsa keys in one line>
package_update: true
package_upgrade: true
packages:
  - nodejs
  - python3

Second, create a new instance.

multipass launch -c 2 -m 2G -d 10G -n jimny --cloud-init cloud_init.yaml

Last, login to new instance and you will find that apt is both updated and upgraded. Nodejs and Python3 are there waiting for you.

multipass info jimny

multipass shell jimny

ubuntu@jimny:~$ apt list python3 nodejs