Skip to content

Instantly share code, notes, and snippets.

@vrmsreddy
Forked from ampedandwired/Vagrantfile
Created December 15, 2017 08:26
Show Gist options
  • Select an option

  • Save vrmsreddy/9a4616727f936379e1a54e21311a6493 to your computer and use it in GitHub Desktop.

Select an option

Save vrmsreddy/9a4616727f936379e1a54e21311a6493 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment