Run cloud-init locally with multipass

Multipass is a cross-platform tool for launching Ubuntu VMs across Linux, Windows, and macOS.

When launching a Multipass VM, user data can be passed by adding the --cloud-init flag and an appropriate YAML file containing the user data. For more information about the file and how to construct it, see our explanatory guide about the user data cloud-config format.

Create your configuration

In this example we will create empty network-config and meta-data files, and create a user-data file with a basic cloud-init configuration.

If you have network configuration or metadata to provide, edit the network-config and meta-data files accordingly.

To create the files, run the following commands:

$ touch network-config
$ touch meta-data
$ cat >user-data <<EOF
#cloud-config
password: password
chpasswd:
  expire: False
ssh_pwauth: True
EOF

Launch your instance

You can pass the user-data file to Multipass and launch a Bionic instance named test-vm with the following command:

$ multipass launch bionic --name test-vm --cloud-init user-data

Multipass will validate the user-data configuration file before starting the VM. This breaks all cloud-init configuration formats except the user data cloud-config.