Score:0

multipass cloud-init command line doesn't find yaml file

jp flag

This seems like a pretty silly question as it's too simple.

but

Just getting feet wet with multipass, so one of the first things I try is using a cloud init file. But multipass reports error: No such file:

[opt/multipass] $ multipass launch -n test --cloud-init setup.yaml

error: No such file: setup.yaml

so I tried ./setup.yaml and absolute path /opt/multipass/setup.yaml all give same no such file error.

/opt/multipass

drwxrwsr-x+  2 david    users 4096 Feb  6 08:04 ./
drwxrwsr-x+ 44 sysadmin users 4096 Feb  6 07:24 ../
-rw-rw-r--+  1 david    users  256 Feb  6 07:50 setup.yaml

What am I missing here? all the examples look like this. https://ubuntu.com/blog/using-cloud-init-with-multipass Does it give this error if there is an issue in the yaml file? Do the yaml files need to be in a particular directory? or have particular owner, permissions (it's read for everyone now). This seems so simple..should just work no?

setup.yaml

users:
    - default
    - name: ubuntu
    - sudo: ALL=(ALL) NOPASSWD:ALL
      plain_text_passwd: 'ubuntu'
      home: /home/ubuntu
      shell: /bin/bash
      lock_passwd: false
      gecos: Ubuntu
      groups: [adm, audio, cdrom, dialout, floppy, video, plugdev, dip, netdev, sudo]
Score:0
jp flag

well the question was not totally silly as the issue comes because snaps don't have necessarily access to the host filesystem and multipass is a snap application.

By default though when you install multipass it does get access to the user home directory so when looking for clould init files it has to be relative to your home directory and I had the yaml files in /opt/multipass and multipass can't "see" there by default.

So moving the yaml file to ~/multipass/setup.yaml and then using

multipass launch -n test --cloud-init ./multipass/setup.yaml from home directory works.

A bash script/function with an alias alias mpl="multipass_launch" can make launching easy

multipass_launch () {
    subdir=${MULTIPASS_HOME:-cloud-init}
    [[ $1 ]] && name="-n $1"
    if [[ $2 ]]; then
     if [[ -f $HOME/$subdir/$2.yaml ]]; then
       init="--cloud-init $HOME/$subdir/$2.yaml"
     else 
      echo no cloud init file $HOME/$subdir/$2.yaml
      return 1
     fi
   fi  
    echo running: multipass launch $name $init
    multipass launch $name $init
 }
 }

now launching with that cloud init file becomes mpl test setup

if you want to keep files multipass can find elsewhere then use bindfs

Score:0
id flag

This helped me with setting up a cloud config file. https://www.digitalocean.com/community/tutorials/how-to-use-cloud-config-for-your-initial-server-setup

also here is an example but make sure to replace with your SSH Keys

if you dont know how to get your ssh keys do this command: cat ~/.ssh/id_rsa.pub

example file below

#cloud-config
users:
  - name: testcloud
    ssh-authorized-keys:
      - ssh-rsa 
INSERT YOUR  PUBLIC SSH KEY HERE
    sudo: ['ALL=(ALL) NOPASSWD:ALL']
    groups: sudo
    shell: /bin/bash
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.