Is there any way that I can set some ENV vars from host to guest Vagrant OS when booting it up? From my guest OS I need to connect to a database and I want to pass the database URL from host to guest as well as other parameters.
I tried with TEST="foo" vagrant up
but TEST is nowhere in my env vars on guest os. Any ideas?
The Vagrant File used in the VPP repo sets the configuration options based on your ENV (environment) variables, or to default the configuration at specified values if your ENV variables are not initialized (if you did not run the env.sh script found below). This is the env.sh script found in vpp/extras/vagrant.
Fortunately, vagrant provides an environment variable called VAGRANT_HOME by which you can set vagrant home. To make it permanent, add this to your ~/. bash_profile (for login shell). VAGRANT_HOME can be set to change the directory where Vagrant stores global state.
A Vagrantfile is a Ruby file that instructs Vagrant to create, depending on how it is executed, new Vagrant machines or boxes. You can see a box as a compiled Vagrantfile. It describes a type of Vagrant machines. From a box, we can create new Vagrant machines.
Your way of altering `vagrant up´ won't work. The correct way of doing this is during provisioning. Depending on the provisioner you are using, there are different ways.
Here is an example how to echo your host PATH env on your guest during provisioning:
config.vm.provision "shell", inline: "echo " + ENV['PATH']
As you can see, inside your Vagrantfile you can use the ENV
variable to access the host environment variables. You can use this to pass variables to the provisioner of your choice and processing it as needed.
As I'm most used to chef, here is how I would do it:
/etc/profile.d/
under some name that fits the needs@Romeo: See my related answer here: https://stackoverflow.com/a/42250314/6864226
config.vm.provision :shell, path: "scripts/bootstrap.sh", env: {"MYVAR" => ENV['ABC']}
@Sgoettschkes: Thanks for the pointer in the right direction
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With