Created
September 15, 2014 22:20
-
-
Save bcantoni/f9ca55cd4393ec4929a2 to your computer and use it in GitHub Desktop.
Example of passing a host environment variable through to a guest, using Vagrant script provisioner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👏 🎅