Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ampedandwired
Created January 14, 2015 05:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ampedandwired/97806298afaefc265018 to your computer and use it in GitHub Desktop.
Save ampedandwired/97806298afaefc265018 to your computer and use it in GitHub Desktop.
Configure a Vagrant VM to piggyback off CNTLM running on the host
def get_proxy_url
# Doesn't support different proxies for different protocols at present
host_proxy = ENV['http_proxy'] || ENV['HTTP_PROXY'] || ENV['https_proxy'] || ENV["HTTPS_PROXY"]
if host_proxy
uri = URI(host_proxy)
if ['localhost', '127.0.0.1'].include? uri.host
# 10.0.2.2 is the default vagrant gateway and should connect to the host OS.
# Confirm this by running 'netstat -r' in the guest.
host_proxy = host_proxy.sub(uri.host, '10.0.2.2')
end
end
host_proxy
end
def configure_proxy(config)
proxy_server = get_proxy_url
if Vagrant.has_plugin?("vagrant-proxyconf") && proxy_server
config.proxy.http = proxy_server
config.proxy.https = proxy_server
config.proxy.no_proxy = "localhost,127.0.0.1"
else
puts "Please install vagrant-proxyconf for internet access via local proxy"
end
end
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
configure_proxy(config)
...
end
@peimelo
Copy link

peimelo commented Nov 25, 2015

Work for me. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment