diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index ea5d77b15..34deaf058 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -253,6 +253,7 @@ module Vagrant # # @return [Symbol] Name of the default provider. def default_provider(**opts) + opts[:exclude] = Set.new(opts[:exclude]) if opts[:exclude] opts[:force_default] = true if !opts.has_key?(:force_default) default = ENV["VAGRANT_DEFAULT_PROVIDER"] @@ -265,10 +266,13 @@ module Vagrant ordered = [] Vagrant.plugin("2").manager.providers.each do |key, data| - impl = data[0] - opts = data[1] + impl = data[0] + popts = data[1] - ordered << [opts[:priority], key, impl, opts] + # Skip excluded providers + next if opts[:exclude] && opts[:exclude].include?(key) + + ordered << [popts[:priority], key, impl, popts] end # Order the providers by priority. Higher values are tried first. diff --git a/test/unit/vagrant/environment_test.rb b/test/unit/vagrant/environment_test.rb index ae3199bdf..7fc0bcc3f 100644 --- a/test/unit/vagrant/environment_test.rb +++ b/test/unit/vagrant/environment_test.rb @@ -717,6 +717,17 @@ VF end end + it "is the highest matching usable provider that isn't excluded" do + plugin_providers[:foo] = [provider_usable_class(true), { priority: 5 }] + plugin_providers[:bar] = [provider_usable_class(true), { priority: 7 }] + plugin_providers[:baz] = [provider_usable_class(true), { priority: 2 }] + plugin_providers[:boom] = [provider_usable_class(true), { priority: 3 }] + + with_temp_env("VAGRANT_DEFAULT_PROVIDER" => nil) do + expect(subject.default_provider(exclude: [:bar, :foo])).to eq(:boom) + end + end + it "is the default provider set if usable" do plugin_providers[:foo] = [provider_usable_class(true), { priority: 5 }] plugin_providers[:bar] = [provider_usable_class(true), { priority: 7 }]