diff --git a/lib/vagrant/shared_helpers.rb b/lib/vagrant/shared_helpers.rb index 839ef55e6..ae9cd15df 100644 --- a/lib/vagrant/shared_helpers.rb +++ b/lib/vagrant/shared_helpers.rb @@ -134,15 +134,17 @@ module Vagrant # # @return [boolean] enabled or not def self.enable_resolv_replace - if !ENV["VAGRANT_DISABLE_RESOLV_REPLACE"] - begin - require "resolv-replace" - true - rescue + if ENV["VAGRANT_ENABLE_RESOLV_REPLACE"] + if !ENV["VAGRANT_DISABLE_RESOLV_REPLACE"] + begin + require "resolv-replace" + true + rescue + false + end + else false end - else - false end end end diff --git a/test/unit/vagrant/shared_helpers_test.rb b/test/unit/vagrant/shared_helpers_test.rb index da0f4c134..64adf7bc6 100644 --- a/test/unit/vagrant/shared_helpers_test.rb +++ b/test/unit/vagrant/shared_helpers_test.rb @@ -143,4 +143,23 @@ describe Vagrant do expect(subject.prerelease?).to be(false) end end + + describe "#enable_resolv_replace" do + it "should not attempt to require resolv-replace by default" do + expect(subject).not_to receive(:require).with("resolv-replace") + subject.enable_resolv_replace + end + + it "should require resolv-replace when VAGRANT_ENABLE_RESOLV_REPLACE is set" do + expect(subject).to receive(:require).with("resolv-replace") + with_temp_env("VAGRANT_ENABLE_RESOLV_REPLACE" => "1"){ subject.enable_resolv_replace } + end + + it "should not require resolv-replace when VAGRANT_DISABLE_RESOLV_REPLACE is set" do + expect(subject).not_to receive(:require).with("resolv-replace") + with_temp_env("VAGRANT_ENABLE_RESOLV_REPLACE" => "1", "VAGRANT_DISABLE_RESOLV_REPLACE" => "1") do + subject.enable_resolv_replace + end + end + end end diff --git a/website/source/docs/other/environmental-variables.html.md b/website/source/docs/other/environmental-variables.html.md index 844864078..d474faf9b 100644 --- a/website/source/docs/other/environmental-variables.html.md +++ b/website/source/docs/other/environmental-variables.html.md @@ -219,8 +219,11 @@ shared folders. Defaults to true if the option is not set. This can be overridde on a per-folder basis within your Vagrantfile config by settings the `SharedFoldersEnableSymlinksCreate` option to true. +## `VAGRANT_ENABLE_RESOLV_REPLACE` + +Use the Ruby Resolv library in place of the libc resolver. + ## `VAGRANT_DISABLE_RESOLV_REPLACE` -Vagrant will automatically load `resolv-replace` to use Ruby's Resolv library -in place of the libc resolver. This behavior can be disabled by setting this -environment variable. +Vagrant can optionally use the Ruby Resolv library in place of the libc resolver. +This can be disabled setting this environment variable.