Skip to content

Instantly share code, notes, and snippets.

@stuart-warren
Created August 18, 2015 07:38
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save stuart-warren/8633a22ae8b9db391fd2 to your computer and use it in GitHub Desktop.
Ubuntu cloud with user-data cloud config in Vagrant
# -*- mode: ruby -*-
# vi: set ft=ruby :
CLOUD_CONFIG_PATH = File.join(File.dirname(__FILE__), "user-data")
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = "ubuntu-vivid-cloud"
config.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/vivid/20150815/vivid-server-cloudimg-amd64-vagrant-disk1.box"
# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# config.vm.network "forwarded_port", guest: 80, host: 8080
# Create a private network, which allows host-only access to the machine
# using a specific IP.
config.vm.network "private_network", ip: "192.168.72.10"
config.vm.provider "virtualbox" do |vb|
vb.memory = "1024"
end
if File.exist?(CLOUD_CONFIG_PATH)
# pollinate was timing out, increase timeout
config.vm.provision :shell, :inline => "sed -i s_WAIT=3_WAIT=99_ /etc/default/pollinate", :privileged => true
# clear existing user-data
config.vm.provision :shell, :inline => "rm -rf /var/lib/cloud/instance/* /var/lib/cloud/seed/nocloud-net/user-data", :privileged => true
# copy in user-data script
config.vm.provision :file, :source => "#{CLOUD_CONFIG_PATH}", :destination => "/tmp/vagrantfile-user-data"
config.vm.provision :shell, :inline => "mv /tmp/vagrantfile-user-data /var/lib/cloud/seed/nocloud-net/user-data", :privileged => true
# restart pollinate
config.vm.provision :shell, :inline => "systemctl restart pollinate", :privileged => true
# execute cloud-init
config.vm.provision :shell, :inline => "cloud-init init --local", :privileged => true
config.vm.provision :shell, :inline => "cloud-init init", :privileged => true
config.vm.provision :shell, :inline => "cloud-init modules", :privileged => true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment