Last active
July 20, 2019 21:32
-
-
Save karlwilbur/33f889cffd7052ddcd2f5bf55164ff59 to your computer and use it in GitHub Desktop.
Vagrant - Set Guest ENV vars
This file contains hidden or 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 : | |
VAGRANT_API_VERSION='2' | |
$set_environment_variables = <<SCRIPT | |
cat > '/etc/profile.d/envvars.sh' <<EOV | |
# AWS environment variables. | |
export SOME_VAR=things | |
export OTHER_VAR='other stuff' | |
EOV | |
SCRIPT | |
Vagrant.configure(VAGRANT_API_VERSION) do |config| | |
config.vm..box 'ubuntu/bionic64' | |
# This method utilizes the variable file constructed in the `SCRIPT` above | |
# which would be under source control as it is contained within this `Vagrantfile` | |
config.vm.define 'my-host-name' do |machine| | |
machine.vm.provision "shell", inline: $set_environment_variables, run: "always" | |
end | |
# This method utilizes a variable file which alreedy exists in the | |
# codebase (although possibly not under source control). The `/vagrant` directory | |
# on the guest machine maps to `.` on the host machine. | |
config.vm.define 'my-host-name' do |machine| | |
machine.vm.provision "shell", | |
inline: "echo 'source /vagrant/config/vagrant/bootstrap-env.sh' > /etc/profile.d/envvars.sh", | |
run: "always" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This takes advantage of the
/etc/profile
mechanism which runs any script in/etc/profile.d/
; this applies to all users on the system includingroot
.