Vagrant proxy configuration

#Introduction

In this tutorial, How to use Vagrant proxy configuration on the Virtual machine. To configure a proxy for Vagrant, you can use the Vagrant Proxy Configuration options.

The Vagrant plugin can set:

  • generic http_proxy
  • proxy configuration for Docker
  • proxy configuration for Git
  • proxy configuration for npm
  • proxy configuration for Subversion
  • proxy configuration for Yum
  • etc.

Install Vagrant Plugin vagrant-proxyconf

This plugin requires Vagrant version 1.2 or newer

vagrant plugin install vagrant-proxyconf

The output terminal is as below:

Install Vagrant Plugin vagrant-proxyconf

To configure all Vagrant VMs

Vagrant.configure("2") do |config|
  if Vagrant.has_plugin?("vagrant-proxyconf")
    config.proxy.http     = "http://IP-ADDRESS:3128/"
    config.proxy.https    = "http://IP-ADDRESS:3128/"
    config.proxy.no_proxy = "localhost,127.0.0.1,devopsroles.com,huuphan.com"
  end
  # ... other stuff
end

Environment variables

  • VAGRANT_HTTP_PROXY
  • VAGRANT_HTTPS_PROXY
  • VAGRANT_FTP_PROXY
  • VAGRANT_NO_PROXY

These also override the Vagrantfile configuration.

For example, Vagrant runs the command below:

VAGRANT_HTTP_PROXY="http://devopsroles.com:8080" vagrant up

Disabling the plugin

config.proxy.enabled         # => all applications enabled(default)
config.proxy.enabled = true  # => all applications enabled
config.proxy.enabled = { svn: false, docker: false }  # => specific applications disabled
config.proxy.enabled = ""    # => all applications disabled
config.proxy.enabled = false # => all applications disabled

Example Vagrantfile

Vagrant.configure("2") do |config|
  config.proxy.http = "http://192.168.3.7:8080/"

  config.vm.provider :my_devopsroles do |cloud, override|
    override.proxy.enabled = false
  end
  # ... other stuff
end

My Example, the Vagrant proxy configuration

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|

  config.vm.define "myserver" do |myserver|
    myserver.vm.box = "ubuntu/impish64"
    myserver.vm.hostname = "devopsroles.com.local"
    myserver.vm.network "private_network", ip: "192.168.56.10"
    myserver.vm.network "forwarded_port", guest: 80, host: 8080
    myserver.vm.provider :virtualbox do |v|
	  v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
	  v.customize ["modifyvm", :id, "--memory", 1024]
	  v.customize ["modifyvm", :id, "--name", "myserver"]
	  end
    if Vagrant.has_plugin?("vagrant-proxyconf")
      config.proxy.http     = "http://192.168.4.7:8080/"
      config.proxy.https    = "http://192.168.4.7:8080/"
      config.proxy.no_proxy = "localhost,127.0.0.1,devopsroles.com,huuphan.com"
    end
  end

end
Vagrant proxy configuration

Via Youtube

Conclusion

You have configured a proxy for your Vagrant environment. Make sure to adapt the proxy settings according to your specific proxy server configuration. I hope will this your helpful. Thank you for reading the DevopsRoles page!

,

About HuuPV

My name is Huu. I love technology and especially Devops Skill such as Docker, vagrant, git so forth. I likes open-sources. so I created DevopsRoles.com site to share the knowledge that I have learned. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.