Skip to content

Instantly share code, notes, and snippets.

@bivas
Last active October 14, 2016 14:16
Show Gist options
  • Save bivas/6192d6e422f8ff87c29d to your computer and use it in GitHub Desktop.
Save bivas/6192d6e422f8ff87c29d to your computer and use it in GitHub Desktop.
Vagrant file (CentOS65 based) with the ability to pass environment variables to your provisionening scripts
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "centos65"
config.vm.box_url = "http://puppet-vagrant-boxes.puppetlabs.com/centos-65-x64-virtualbox-nocm.box"
config.vm.define "<your-vm-name>" do |vmname|
end
$before_script = <<SCRIPT
echo # vagrant profile script > /etc/profile.d/vagrant.sh
echo export ENV_VAR1=foo.com/bar >> /etc/profile.d/vagrant.sh
echo export ENV_VAR2=bar.com/foo >> /etc/profile.d/vagrant.sh
chmod +x /etc/profile.d/vagrant.sh
SCRIPT
$after_script = <<SCRIPT
rm -rf /etc/profile.d/vagrant.sh
SCRIPT
config.vm.provision "shell", inline: $before_script
config.vm.provision "shell", path: "build.sh"
config.vm.provision "shell", inline: $after_script
config.vm.provider "virtualbox" do |vm|
vm.name = "<your-vm-name>"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment