Skip to content

Instantly share code, notes, and snippets.

@bcantoni
Created Sep 15, 2014
Embed
What would you like to do?
Example of passing a host environment variable through to a guest, using Vagrant script provisioner
# -*- mode: ruby -*-
# vi: set ft=ruby :
# test setting a guest environment variable based on a host environment variable
# if FOO_BAR is set locally, create command to add it to .profile in the guest
env_var_cmd = ""
if ENV['FOO_BAR']
value = ENV['FOO_BAR']
env_var_cmd = <<CMD
echo "export FOO_BAR=#{value}" | tee -a /home/vagrant/.profile
CMD
end
script = <<SCRIPT
#{env_var_cmd}
SCRIPT
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "hashicorp/precise64"
config.vm.hostname = "envtest"
config.vm.provision :shell, :inline => script
config.vm.provider "virtualbox" do |vb|
# vb.gui = true
vb.name = "envtest"
vb.customize ["modifyvm", :id, "--memory", "1000"]
end
end
@millerjp

This comment has been minimized.

Copy link

@millerjp millerjp commented Sep 16, 2014

Very handy Gist!

@emmanuellyautomated

This comment has been minimized.

Copy link

@emmanuellyautomated emmanuellyautomated commented Sep 2, 2016

👏 🎅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment