Skip to content

Instantly share code, notes, and snippets.

@YordanGeorgiev
Created October 15, 2019 11:43
Show Gist options
  • Save YordanGeorgiev/6140d2a8725d1a262a485313c8c07e17 to your computer and use it in GitHub Desktop.
Save YordanGeorgiev/6140d2a8725d1a262a485313c8c07e17 to your computer and use it in GitHub Desktop.
[how-to pass environement variables to vagrant guest] how-to pass environement variables to vagrant guest
$set_environment_variables = <<SCRIPT
tee "/etc/profile.d/myvars.sh" > "/dev/null" <<EOF
# Ansible environment variables.
export ANSIBLE_STDOUT_CALLBACK=debug
# AWS environment variables.
export AWS_DEFAULT_REGION=#{ENV['AWS_DEFAULT_REGION']}
export AWS_ACCESS_KEY_ID=#{ENV['AWS_ACCESS_KEY_ID']}
export AWS_SECRET_ACCESS_KEY=#{ENV['AWS_SECRET_ACCESS_KEY']}
EOF
SCRIPT
Vagrant.configure("2") do |config|
config.vm.box = "centos/7"
config.vm.provider "hyperv" do |machine|
machine.vmname = "centos7"
end
config.vm.provision "shell", inline: $set_environment_variables, run: "always"
config.vm.provision "ansible_local" do |ansible|
ansible.playbook = "playbook.yml"
ansible.verbose = true
ansible.install_mode = "pip"
ansible.version = "2.2.1.0"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment