cloud-initmultipass

How can I use cloud-init to set up a VM with multipass that includes zsh?


I'm learning to use multipass. My version of multipass is multipass 1.9.0+mac. I'm trying to create a very simple cloud-init configuration:

package:
  - build-essential
  - zsh

I start this with

multipass launch -n test --cloud-init config.yaml

I open a shell into that environment, but there is no zsh in /bin/.

Why was zsh not installed?


Solution

  • package is not a valid top-level key, but packages is. See the docs here.

    It really should warn for this error but does not currently.

    Try this:

    #cloud-config
    packages:
      - build-essential
      - zsh
    

    Upstream cloud-init is working on better warnings/errors for this using jsonschema validation for configs (many changes on this front in upcoming releases). Currently, however, top level keys are not validated currently.

    Also, it looks like multipass automatically inserts the #cloud-config header for you so I don't think you need it on multipass specifically, but for portability to other datasources I would consider adding it anyways. Based on the userdata values in a multipass instance I tested I see the header both ways, so for portability I recommend adding it even though it's a no-op on multipass.