Proxy Configuration Plugin for Vagrant
A Vagrant plugin that configures the virtual machine to use specified proxies.
At this state we support:
- Generic
*_proxy
environment variables that many programs support - APT proxy/cacher
Support is planned for other package managers (at least yum).
Compatibility
This plugin requires Vagrant 1.2 or newer (downloads).
The plugin is supposed to be compatible with all Vagrant providers. 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.
Installation
Install using standard Vagrant plugin installation method:
vagrant plugin install vagrant-proxyconf
See the wiki for instructions to install a pre-release version.
Usage
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.
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.
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"
# ... other stuff
end
Configuration keys
config.proxy.http
- The proxy for HTTP URIsconfig.proxy.https
- The proxy for HTTPS URIsconfig.proxy.ftp
- The proxy for FTS URIsconfig.proxy.no_proxy
- A comma separated list of hosts or domains which do not use proxies.
Possible values
- If all keys are unset or
nil
, no configuration is written. - A proxy should be specified in the form of protocol://[user:pass@]host[:port].
- Empty string (
""
) orfalse
in any setting also force the configuration files to be written, but without configuration for that key. Can be used to clear the old configuration and/or override a global setting.
Environment variables
VAGRANT_HTTP_PROXY
VAGRANT_HTTPS_PROXY
VAGRANT_FTP_PROXY
VAGRANT_NO_PROXY
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
Global *_proxy
environment variables
Many programs (wget, curl, yum, etc.) can be configured to use proxies with <protocol>_proxy
or <PROTOCOL>_PROXY
environment variables. This configuration will be written to /etc/profile.d/proxy.sh on the guest.
Example Vagrantfile
Vagrant.configure("2") do |config|
config.env_proxy.http = "http://192.168.33.200:8888/"
config.env_proxy.https = "$http_proxy"
config.env_proxy.no_proxy = "localhost,127.0.0.1,.example.com"
# ... other stuff
end
Configuration keys
config.env_proxy.http
- The proxy for HTTP URIsconfig.env_proxy.https
- The proxy for HTTPS URIsconfig.env_proxy.ftp
- The proxy for FTS URIsconfig.env_proxy.no_proxy
- A comma separated list of hosts or domains which do not use proxies.
Possible values
- If all keys are unset or
nil
, no configuration is written. - A proxy can be specified in the form of protocol://[user:pass@]host[:port].
- The values are used as specified, so you can use for example variables that will be evaluated by the shell on the VM.
- Empty string (
""
) orfalse
in any setting also force the configuration file to be written, but without configuration for that key. Can be used to clear the old configuration and/or override a global setting.
Environment variables
VAGRANT_ENV_HTTP_PROXY
VAGRANT_ENV_HTTPS_PROXY
VAGRANT_ENV_FTP_PROXY
VAGRANT_ENV_NO_PROXY
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_ENV_HTTP_PROXY="http://proxy.example.com:8080" vagrant up
Apt
Configures Apt to use the specified proxy settings. The configuration will be written to /etc/apt/apt.conf.d/01proxy on the guest.
Example Vagrantfile
Vagrant.configure("2") do |config|
config.apt_proxy.http = "192.168.33.1:3142"
config.apt_proxy.https = "DIRECT"
# ... other stuff
end
Configuration keys
config.apt_proxy.http
- The proxy for HTTP URIsconfig.apt_proxy.https
- The proxy for HTTPS URIsconfig.apt_proxy.ftp
- The proxy for FTP URIs
Possible values
- If all keys are unset or
nil
, no configuration is written. - A proxy can be specified in the form of [http://][user:pass@]host[:port]. So all but the host part are optional. The default port is 3142 and protocol is the same as the key.
- Empty string (
""
) orfalse
in any protocol also force the configuration file to be written, but without configuration for that protocol. Can be used to clear the old configuration and/or override a global setting. "DIRECT"
can be used to specify that no proxy should be used. This is mostly useful for disabling proxy for HTTPS URIs when HTTP proxy is set (as Apt defaults to the latter).- Please refer to apt.conf(5) manual for more information.
Environment variables
VAGRANT_APT_HTTP_PROXY
VAGRANT_APT_HTTPS_PROXY
VAGRANT_APT_FTP_PROXY
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, run:
VAGRANT_APT_HTTP_PROXY="proxy.example.com:8080" vagrant up
Running apt-cacher-ng on a Vagrant box
Here is an example for setting up apt-cacher proxy server in a Vagrant VM.
Related plugins and projects
- apt-cacher-box
a Vagrant setup for apt-cacher-ng. - vagrant-cachier
An excellent Vagrant plugin that shares various cache directories among similar VM instances. Should work fine together with vagrant-proxyconf. - vagrant-httpproxy
A Chef cookbook for configuring Chef resources to use the specified proxy (while offline). - vagrant-proxy
A Vagrant plugin that uses iptables rules to force the VM to use a proxy.