Created
January 14, 2015 05:09
-
-
Save ampedandwired/97806298afaefc265018 to your computer and use it in GitHub Desktop.
Configure a Vagrant VM to piggyback off CNTLM running on the host
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
Work for me. Thanks.