cloud-init support
It'd be great to have cloud-init experimental feature supported in the QEMU provider. Though it means disks feature is required too (as cloud-init works this way for non-cloud VMs).
This way it's possible to use e.g. Ubuntu and Debian cloud images unmodified.
Links:
- https://developer.hashicorp.com/vagrant/docs/cloud-init
- https://developer.hashicorp.com/vagrant/docs/disks
- https://cloudinit.readthedocs.io/en/latest/topics/datasources/nocloud.html
Thanks, I will take a closer look at it.
You can use VirtualBox builtin provider as a reference I guess.. my Ruby foo is not that great so it's hard to say where to look exactly.. feel free to ask for testing and for cloud-init-related help.
Roughly it's enough to add the following to QEMU call:
-drive file=/path/to/cidata.iso,media=cdrom
The ISO MUST have cidata label and MUST contain 2 files:
- /meta-data
- /user-data
Then cloud-init will consider this CD as a data source to apply the configuration from.
Few more on how to get that working if/when support will be implemented:
- wget -O debian-11-genericcloud-arm64.qcow2 https://cloud.debian.org/images/cloud/bullseye/20221108-1193/debian-11-genericcloud-arm64-20221108-1193.qcow2
-
Use the `Vagrantfile`:
# Basic Vagrant config (API version 2) Vagrant.configure(2) do |config| vagrant_root = File.dirname(__FILE__) config.vm.provider "qemu" do |qemu| qemu.qemu_dir = "/opt/homebrew/share/qemu" qemu.image_path = "#{vagrant_root}/debian-11-genericcloud-arm64.qcow2" end config.vm.cloud_init :user_data do |cloud_init| cloud_init.content_type = "text/cloud-config" cloud_init.inline = <<-EOF disable_root: true growpart: mode: "auto" devices: ["/"] ssh_pwauth = true users: - name: vagrant plain_text_passwd: vagrant lock_passwd: false shell: /bin/bash sudo: "ALL=(ALL) NOPASSWD:ALL" ssh_authorized_keys: - ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key EOF end end -
vagrant up
Vagrant should be able to spin the VM up and to ssh into as vagrant user with the vagrant insecure key.
Usually cloud-init output is visible on the VM console (serial console in this case). E.g. below is the output from my packer when everything is good. You can see the DataSourceNoCloud [seed=/dev/vdb] is recognized here (this is an CDROM image made by packer).
[ 4.365327] cloud-init[587]: Cloud-init v. 20.4.1 finished at Tue, 06 Dec 2022 04:38:18 +0000. Datasource DataSourceNoCloud [seed=/dev/vdb][dsmode=net]. Up 4.36 seconds
If anything is wrong with the CD image you'll see some datasource-related error at early cloud-init stage.
Feel free to contact me if need any help!