Search code examples
debianvagrantcloud-init

How to use cloud-init with debian Vagrant boxes?


It seems that cloud-init is not pre-installed in the debian/bookworm64 Vagrant image as well as debian/bullseye64. I did not find any other relevant image in search. Is there a way to make cloud-init to execute the user script nonetheless, maybe with some local hacks?

Steps to reproduce:

  • create a Vagrantfile using vagrant init debian/bookworm64
  • follow official steps to enable cloud-init (e.g. enable experimental features etc.) and add a section to Vagrantfile:
    config.vm.cloud_init :user_data do |cloud_init|
      cloud_init.content_type = "text/cloud-config"
      cloud_init.path = "userdata-local.yml"
    end
    
  • create a simple userdata-local.yml file in the same directory e.g.
    runcmd:
      - echo "Hello world"
    

The end result of running vagrant up is the error cloud-init is not found. Please ensure that cloud-init is installed and available on path for guest xyz.


Solution

  • I did not find any other relevant image in search.

    Consider using cloud images which have cloud-init pre-installed.

    Is there a way to make cloud-init to execute the user script nonetheless, maybe with some local hacks

    If cloud-init is not installed, cloud-init certainly will not be running on your image on first boot.

    What you could possibly do (if you would rather not use a cloud image) is install cloud-init after your image boots, then take a snapshot and use that as a base image to boot cloud-init instances from.