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

cloud-init support #29

Open
jay7x opened this issue Dec 5, 2022 · 3 comments
Open

cloud-init support #29

jay7x opened this issue Dec 5, 2022 · 3 comments

Comments

@jay7x
Copy link

jay7x commented Dec 5, 2022

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:

@ppggff
Copy link
Owner

ppggff commented Dec 5, 2022

Thanks, I will take a closer look at it.

@jay7x
Copy link
Author

jay7x commented Dec 5, 2022

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.

@jay7x
Copy link
Author

jay7x commented Dec 6, 2022

Few more on how to get that working if/when support will be implemented:

  1. wget -O debian-11-genericcloud-arm64.qcow2 https://cloud.debian.org/images/cloud/bullseye/20221108-1193/debian-11-genericcloud-arm64-20221108-1193.qcow2

  2. 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
  3. 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants