Skip to content

Instantly share code, notes, and snippets.

@johnbellone johnbellone/.env
Last active Dec 19, 2016

Embed
What would you like to do?
Using dotenv gem with Vagrant and proxies.
VAGRANT_HTTP_PROXY=$HTTP_PROXY
VAGRANT_HTTPS_PROXY=$HTTPS_PROXY
VAGRANT_NO_PROXY=$NO_PROXY

Corporate Usage

In a corporate environment it may be necessary to set multiple proxies each for a different service. In this particular case the best solution that I have been able to find is to use an environment file loaded up with the [dotenv plugin][1]. This file can be setup to use the environment variable values from the runtime shell, e.g. the bash shell that you're executing the vagrant commands from.

Usage

  $ vagrant plugin install dotenv
  $ vagrant plugin install vagrant-proxyconf
begin
require 'dotenv'
if File.exists?(File.join(Dir.home, '.vagrant.d', 'env'))
Dotenv.load(File.join(Dir.home, '.vagrant.d', 'env'))
end
Dotenv.load
rescue LoadError => e
# TODO: Spew something to standard error as a warning. This should not stop execution
# as it may have been intended to not exist.
end
Vagrant.configure('2') do |config|
if Vagrant.has_plugin?('vagrant-proxyconf')
vagrant.proxy.enabled = ENV.fetch('HTTP_PROXY', false)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.