Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@peimelo 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