Home

Awesome

Proxy Configuration Plugin for Vagrant

<span class="badges">

Gem Version Build Status

</span>

A Vagrant plugin that configures the virtual machine to use specified proxies. This is useful for example in case you are behind a corporate proxy server, or you have a caching proxy (for example polipo).

The plugin can set:

Quick start

Install the plugin:

vagrant plugin install vagrant-proxyconf

To configure all possible software on all Vagrant VMs, add the following to $HOME/.vagrant.d/Vagrantfile (or to a project specific Vagrantfile):

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

Compatibility

This plugin requires Vagrant 1.2 or newer (downloads).

The plugin is supposed to be compatible with all Vagrant providers and other plugins. Please file an issue if this is not the case. The following providers are confirmed to work: AWS, Digital Ocean, VirtualBox, VMware Fusion.

For the proxy configuration to take effect for vagrant-omnibus plugin, version 1.1.1 or newer of it should be used.

Usage

Install using standard Vagrant plugin installation method: vagrant plugin install vagrant-proxyconf. See the wiki for instructions to install a pre-release version.

The plugin hooks itself to all Vagrant commands triggering provisioning (e.g. vagrant up, vagrant provision, etc.). The proxy configurations are written just before provisioners are run.

Proxy settings can be configured in Vagrantfile. In the common case that you want to use the same configuration in all Vagrant machines, you can use $HOME/.vagrant.d/Vagrantfile or environment variables. Platform specific settings are only used on virtual machines that support them (i.e. Apt configuration on Debian based systems), so there is no harm using global configuration.

Project specific Vagrantfile overrides global settings. Environment variables override both.

It is a good practise to wrap plugin specific configuration with Vagrant.has_plugin? checks so the user's Vagrantfiles do not break if plugin is uninstalled or Vagrantfile shared with people not having the plugin installed. (For Vagrant 1.2 you have to use if defined?(VagrantPlugins::ProxyConf) instead.)

Default/global configuration

It's a common case that you want all possible connections to pass through the same proxy. This will set the default values for all other proxy configuration keys. It also sets default proxy configuration for all Chef Solo and Chef Client provisioners.

Many programs (wget, curl, yum, etc.) can be configured to use proxies with http_proxy or HTTP_PROXY etc. environment variables. This configuration will be written to /etc/profile.d/proxy.sh and /etc/environment on the guest.

Also sudo will be configured to preserve the variables. This requires that sudo in the VM is configured to support "sudoers.d", i.e. /etc/sudoers contains line #includedir /etc/sudoers.d.

Example Vagrantfile

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

Configuration keys

Possible values

Environment variables

These also override the Vagrantfile configuration. To disable or remove the proxy use an empty value.

For example to spin up a VM, run:

VAGRANT_HTTP_PROXY="http://proxy.example.com:8080" vagrant up

Disabling the plugin

New Behavior Warning: Setting the plugin to disabled now unconfigures all or specific proxies.

The plugin can be disabled by setting config.proxy.enabled to false or empty string (""). This can be also be used to disable a proxy for some provider. Specific applications can be disabled by setting config.proxy.enabled to a hash( like { svn: false } or { svn: {enabled: false} }).

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

Skipping the plugin

The plugin can also be skipped from applying/removing the proxy configuration for a specific provider.

When the plugin is disabled as in the following example:

{
  :apt => {
    :enabled => false,
    :skip    => true,
  },
  :svn => {
    :enabled => false,
    :skip    => true,
  },
}

The plugin is disabled, but skip = true means that no proxy configuration will be removed so the system will remain in it's most recent state. This can be useful if you just want to skip over specific provider being configured or unconfigured.

When the plugin is enabled as in the following example:

{
  :apt => {
    :enabled => true,
    :skip    => false,
  },
  :svn => {
    :enabled => true,
    :skip    => true,
  },
}

The plugin is enabled, but skip = true means that no proxy configuration will be applied so the system will remain in it's most recent state. This can be useful if you just want to skip over specific provider being configured or unconfigured.

In the example above the apt proxy will be enabled and proxy configuration will be applied, but the svn proxy even though it's enabled will be skipped.

Example Vagrantfile

Vagrant.configure("2") do |config|
  config.proxy.http = "http://192.168.0.2:3128/"

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

Configuration for applications

Configures applications to use proxy settings. The configurations will be written to configuration files for each application.

Configurable applications

Following applications can be configured. Configurations are based on default configuration(config.proxy.*) and can be overridden except SVN. SVN configuration is not set if no SVN specific configuration.

ApplicationBase conf.Specific conf.Env. var.
configure_apt_proxyconfig.proxy.*config.apt_proxy.*VAGRANT_APT_*
configure_git_proxyN/Aconfig.git_proxy.*VAGRANT_GIT_*
configure_svn_proxyN/Aconfig.svn_proxy.*VAGRANT_SVN_*
configure_yum_proxyconfig.proxy.*config.yum_proxy.*VAGRANT_YUM_*

Example Vagrantfile

Vagrant.configure("2") do |config|
  config.proxy.http     = "http://192.168.0.2:3128/"
  config.proxy.https    = "http://192.168.0.2:3128/"
  config.proxy.no_proxy = "localhost,127.0.0.1,.example.com"
  config.apt_proxy.http = "http://192.168.33.1:3142"
  config.apt_proxy.https = "DIRECT"
  # ... other stuff
end

Environment variables

These also override the Vagrantfile configuration. To disable or remove the proxy use "DIRECT" or an empty value.

For example to spin up a VM and set the APT proxy to `http://proxy.example.com:8080, run:

VAGRANT_APT_HTTP_PROXY="http://proxy.example.com:8080" vagrant up
ProviderEnvironment VariableDescrptionPrecendence
aptVAGRANT_APT_HTTP_PROXYConfigures APT http proxyHighest
VAGRANT_APT_HTTPS_PROXYConfigures APT https proxyHighest
VAGRANT_APT_FTP_PROXYConfigures APT ftp proxyHighest
VAGRANT_APT_VERIFY_PEERConfigures APT Verify-PeerHighest
VAGRANT_APT_VERIFY_HOSTConfigures APT Verify-HostHighest
chefVAGRANT_CHEF_HTTP_PROXYConfigures CHEF http proxyHighest
VAGRANT_CHEF_HTTPS_PROXYConfigures CHEF https proxyHighest
VAGRANT_CHEF_NO_PROXYConfigures CHEF no proxyHighest
dockerVAGRANT_DOCKER_HTTP_PROXYConfigures DOCKER http proxyHighest
VAGRANT_DOCKER_HTTPS_PROXYConfigures DOCKER https proxyHighest
VAGRANT_DOCKER_NO_PROXYConfigures DOCKER no proxyHighest
envVAGRANT_ENV_HTTP_PROXYConfigures ENV http proxyHighest
VAGRANT_ENV_HTTPS_PROXYConfigures ENV https proxyHighest
VAGRANT_ENV_FTP_PROXYConfigures ENV FTP proxyHighest
VAGRANT_ENV_NO_PROXYConfigures ENV no proxyHighest
gitVAGRANT_GIT_HTTP_PROXYConfigures GIT http proxyHighest
VAGRANT_GIT_HTTPS_PROXYConfigures GIT https proxyHighest
npmVAGRANT_NPM_HTTP_PROXYConfigures NPM http proxyHighest
VAGRANT_NPM_HTTPS_PROXYConfigures NPM https proxyHighest
VAGRANT_NPM_NO_PROXYConfigures NPM no proxyHighest
pearVAGRANT_PEAR_HTTP_PROXYConfigures PEAR http proxyHighest
svnVAGRANT_SVN_HTTP_PROXYConfigures SVN http proxyHighest
VAGRANT_SVN_NO_PROXYConfigures SVN no proxyHighest
yumVAGRANT_YUM_HTTP_PROXYConfigures YUM http proxyHighest

Related plugins and projects

Installing a pre-release version

Development Known Issues

When running bundle exec vagrant status I get Encoded files can't be read outside of the Vagrant installer.

$ bundle exec vagrant status
Vagrant failed to initialize at a very early stage:

The plugins failed to load properly. The error message given is
shown below.

Encoded files can't be read outside of the Vagrant installer.

The solution is to add this to the Gemfile

embedded_locations = %w(/Applications/Vagrant/embedded /opt/vagrant/embedded)

embedded_locations.each do |p|
    ENV['VAGRANT_INSTALLER_EMBEDDED_DIR'] = p if File.directory?(p)
end

unless ENV.key?('VAGRANT_INSTALLER_EMBEDDED_DIR')
    $stderr.puts "Couldn't find a packaged install of vagrant, and we need this"
    $stderr.puts 'in order to make use of the RubyEncoder libraries.'
    $stderr.puts 'I looked in:'
    embedded_locations.each do |p|
        $stderr.puts "  #{p}"
    end
end

Development Environment Setup

NOTE: This should all be performed in the directory that you have git cloned the source.

NOTE: This also assumes you are using recent MacOS >= Catalina or recent Linux.

Contributors