Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error loading cloud-init config: bad file - multipass and cloud-init #5737

Closed
tersucorp opened this issue Sep 24, 2024 · 7 comments
Closed
Labels
bug Something isn't working correctly invalid This doesn't seem right

Comments

@tersucorp
Copy link

Bug report

I get the error below when trying to create vms with multipass and cloud init.

error loading cloud-init config: bad file
error loading cloud-init config: bad file
error loading cloud-init config: bad file
error loading cloud-init config: bad file

To Reproduce

  1. install multipass 1.14.0
  2. install cloud init 24.2-0ubuntu1~24.04.2
  3. create a cloud-init config file in config/debian-cloud-init.yaml:
#cloud-config
package_update: true
packages:
  - debootstrap
users:
  - name: root
    lock_passwd: false
    passwd: tersu
ssh_pwauth: true
disable_root: false
runcmd:
  - debootstrap --arch=arm64 bookworm /mnt http://deb.debian.org/debian/
  - mount --bind /dev /mnt/dev
  - mount --bind /proc /mnt/proc
  - mount --bind /sys /mnt/sys
  - |
      chroot /mnt /bin/bash -c "apt-get update && \
      apt-get install -y linux-image-arm64 systemd-sysv"
  - chroot /mnt /bin/bash -c "apt-get install -y grub-efi"
  - |
      chroot /mnt /bin/bash -c "grub-install --target=arm64-efi \
      --efi-directory=/boot/efi --bootloader-debian --recheck"
  - chroot /mnt /bin/bash -c "update-grub"
  - |
      chroot /mnt /bin/bash -c "echo 'deb http://deb.debian.org/debian/ \
      bookworm main' > /etc/apt/sources.list"
  - chroot /mnt /bin/bash -c "echo 'root:password' | chpasswd"
  - |
      chroot /mnt /bin/bash -c "sed -i 's/^#PermitRootLogin.*/\
      PermitRootLogin yes/' /etc/ssh/sshd_config"
  - chroot /mnt /bin/bash -c "systemctl enable ssh"
  - umount /mnt/dev
  - umount /mnt/proc
  - umount /mnt/sys
  - echo "Debian installation completed!"
  1. Create a bash script to create vms using multipass and cloud-init
#!/bin/bash

# Launch VMs with multipass
multipass launch --name jumpbox --cpus 1 --memory 512M --disk 5G --cloud-init ./config/debian-cloud-init.yaml --verbose
multipass launch --name master --cpus 1 --memory 2G --disk 10G --cloud-init ./config/debian-cloud-init.yaml --verbose
multipass launch --name worker1 --cpus 1 --memory 2G --disk 10G --cloud-init ./config/debian-cloud-init.yaml --verbose
multipass launch --name workder2 --cpus 1 --memory 2G --disk 10G --cloud-init ./config/debian-cloud-init.yaml --verbose
  1. Run the bash script

Expected behavior
It should create the multipass VMs with the specified config

cloud-init logs

cloud-init.tar.gz

@tersucorp tersucorp added bug Something isn't working correctly new An issue that still needs triage labels Sep 24, 2024
@holmanb
Copy link
Member

holmanb commented Sep 24, 2024

@tersucorp Cloud-init appears to work just fine on multipass using a stock multipass image.

$ cloud-init --version
/usr/bin/cloud-init 24.2-0ubuntu1~24.04.2

Cloud-init failed because ds-identify didn't find a configuration. I can tell you this because on a good launch (stock image) I see this in /run/cloud/ds-identify.log:

ISO9660_DEVS=/dev/sr0=cidata

but on yours I see:

ISO9660_DEVS=

It looks like multipass isn't providing the user-data disk for some reason - and based on the multipass errors that you shared (error loading cloud-init config: bad file), it looks like this has something to do with the problem. This exception seems to be thrown by the yaml-cpp library that is used by multipass.

I would recommend double and triple checking that the exact file that you are passing to multipass is valid YAML, since yaml-cpp doesn't seem to think that it is.

install cloud init 24.2-0ubuntu1~24.04.2

Cloud-init is already installed in mulipass images so this shouldn't be necessary. Was this just so that you could locally check the schema using cloud-init schema --config-file?

@holmanb holmanb added invalid This doesn't seem right and removed new An issue that still needs triage labels Sep 24, 2024
@tersucorp
Copy link
Author

tersucorp commented Sep 24, 2024

@holmanb yes, I checked the validity of the file:

cloud-init schema -c config/debian-cloud-init.yaml -t cloud-config                                                           21:58:40
Valid schema config/debian-cloud-init.yaml
yamllint config/debian-cloud-init.yaml                                                                                       21:58:45
config/debian-cloud-init.yaml
  1:2       warning  missing starting space in comment  (comments)
  2:1       warning  missing document start "---"  (document-start)

I also want to add that I am running this from my local machine - ubuntu 24.04

This is the link to the files I am working with: https://github.com/davidshare/Kubernetes-tasks/tree/master/multipass-k8s-cluster

@tersucorp
Copy link
Author

@holmanb I also copied samples from here to test, and got the same error:

https://cloudinit.readthedocs.io/en/latest/reference/examples.html

@holmanb
Copy link
Member

holmanb commented Sep 24, 2024

@tersucorp It works for me with your config.

$ multipass launch --name master --cloud-init ./debian-cloud-init.yaml --verbose
Launched: master
$ multipass --version                                                           
multipass   1.14.0
multipassd  1.14.0
$ cat /etc/os-release
PRETTY_NAME="Ubuntu 24.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04.1 LTS (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=noble
LOGO=ubuntu-logo

$ cat ./debian-cloud-init.yaml 
#cloud-config
package_update: true
packages:
  - debootstrap
users:
  - name: root
    lock_passwd: false
    passwd: tersu
ssh_pwauth: true
disable_root: false
runcmd:
  - debootstrap --arch=arm64 bookworm /mnt http://deb.debian.org/debian/
  - mount --bind /dev /mnt/dev
  - mount --bind /proc /mnt/proc
  - mount --bind /sys /mnt/sys
  - |
      chroot /mnt /bin/bash -c "apt-get update && \
      apt-get install -y linux-image-arm64 systemd-sysv"
  - chroot /mnt /bin/bash -c "apt-get install -y grub-efi"
  - |
      chroot /mnt /bin/bash -c "grub-install --target=arm64-efi \
      --efi-directory=/boot/efi --bootloader-debian --recheck"
  - chroot /mnt /bin/bash -c "update-grub"
  - |
      chroot /mnt /bin/bash -c "echo 'deb http://deb.debian.org/debian/ \
      bookworm main' > /etc/apt/sources.list"
  - chroot /mnt /bin/bash -c "echo 'root:password' | chpasswd"
  - |
      chroot /mnt /bin/bash -c "sed -i 's/^#PermitRootLogin.*/\
      PermitRootLogin yes/' /etc/ssh/sshd_config"
  - chroot /mnt /bin/bash -c "systemctl enable ssh"
  - umount /mnt/dev
  - umount /mnt/proc
  - umount /mnt/sys
  - echo "Debian installation completed!"

@tersucorp
Copy link
Author

Wow! So how do I even begin to figure out what the issue is?

@holmanb
Copy link
Member

holmanb commented Sep 24, 2024

Wow! So how do I even begin to figure out what the issue is?

@tersucorp When dealing with the unexpected like this, start by challenging your assumptions and expectations. Reinstall multipass. Delete the configuration files and scripts and recreate them. Does it still happen? Are you able to recreate my working example? If you're doing anything weird (building multipass from source, using custom images, etc), see if it reproduces with a more standard setup. If none of those steps identify your problem, then you should file a bug against multipass and see if they can help you.

Link to the crossposted question for posterity.

@holmanb
Copy link
Member

holmanb commented Sep 24, 2024

@tersucorp This doesn't appear to be an issue with cloud-init, so I'm going to close it. Best of luck!

@holmanb holmanb closed this as completed Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants