How to: test cloud-init setup locally

  1. Install “genisoimage” (sudo apt-get -y install genisoimage for Linux or sudo port install cdrtools for MacOS, if you dare use macports)
  2. Create a metadata file (named meta-data)
instance-id: iid-0123456789abcdefg
local-hostname: ubuntu-bionic
no-cloud.iso: meta-data user-data
mkisofs -joliet -rock -volid "cidata" -output nocloud.iso meta-data user-data
# -*- mode: ruby -*-
# vi: set ft=ruby :

IMAGE_PATH = File.join(File.dirname(__FILE__), "no-cloud.iso")

Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/bionic64"

# Disable SSH password - we will use Vagrant key
config.ssh.password = nil

# Disable shared folders
config.vm.synced_folder ".", "/vagrant", disabled: true

# Tweak virtualbox
config.vm.provider :virtualbox do |vb|
# Attach no-cloud.iso to the VM
vb.customize [
"storageattach", :id,
"--storagectl", "SCSI",
"--port", "1",
"--type", "dvddrive",
"--medium", IMAGE_PATH
]

vb.linked_clone = true
end
end

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store