Merge pull request #10242 from briancain/IGNORE-BOX-VAGRNANTFILE
Add config option `ignore_box_vagrantfile`
This commit is contained in:
commit
184d114374
|
@ -1,4 +1,5 @@
|
||||||
require "vagrant/util/template_renderer"
|
require "vagrant/util/template_renderer"
|
||||||
|
require "log4r"
|
||||||
|
|
||||||
module Vagrant
|
module Vagrant
|
||||||
# This class provides a way to load and access the contents
|
# This class provides a way to load and access the contents
|
||||||
|
@ -26,6 +27,7 @@ module Vagrant
|
||||||
@keys = keys
|
@keys = keys
|
||||||
@loader = loader
|
@loader = loader
|
||||||
@config, _ = loader.load(keys)
|
@config, _ = loader.load(keys)
|
||||||
|
@logger = Log4r::Logger.new("vagrant::vagrantfile")
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns a {Machine} for the given name and provider that
|
# Returns a {Machine} for the given name and provider that
|
||||||
|
@ -195,12 +197,14 @@ module Vagrant
|
||||||
box = boxes.find(config.vm.box, box_formats, config.vm.box_version)
|
box = boxes.find(config.vm.box, box_formats, config.vm.box_version)
|
||||||
if box
|
if box
|
||||||
box_vagrantfile = find_vagrantfile(box.directory)
|
box_vagrantfile = find_vagrantfile(box.directory)
|
||||||
if box_vagrantfile
|
if box_vagrantfile && !config.vm.ignore_box_vagrantfile
|
||||||
box_config_key =
|
box_config_key =
|
||||||
"#{boxes.object_id}_#{box.name}_#{box.provider}".to_sym
|
"#{boxes.object_id}_#{box.name}_#{box.provider}".to_sym
|
||||||
@loader.set(box_config_key, box_vagrantfile)
|
@loader.set(box_config_key, box_vagrantfile)
|
||||||
local_keys.unshift(box_config_key)
|
local_keys.unshift(box_config_key)
|
||||||
config, config_warnings, config_errors = @loader.load(local_keys)
|
config, config_warnings, config_errors = @loader.load(local_keys)
|
||||||
|
elsif box_vagrantfile && config.vm.ignore_box_vagrantfile
|
||||||
|
@logger.warn("Ignoring #{box.name} provided Vagrantfile inside box")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,6 +22,7 @@ module VagrantPlugins
|
||||||
attr_accessor :base_mac
|
attr_accessor :base_mac
|
||||||
attr_accessor :boot_timeout
|
attr_accessor :boot_timeout
|
||||||
attr_accessor :box
|
attr_accessor :box
|
||||||
|
attr_accessor :ignore_box_vagrantfile
|
||||||
attr_accessor :box_check_update
|
attr_accessor :box_check_update
|
||||||
attr_accessor :box_url
|
attr_accessor :box_url
|
||||||
attr_accessor :box_server_url
|
attr_accessor :box_server_url
|
||||||
|
@ -51,6 +52,7 @@ module VagrantPlugins
|
||||||
@base_mac = UNSET_VALUE
|
@base_mac = UNSET_VALUE
|
||||||
@boot_timeout = UNSET_VALUE
|
@boot_timeout = UNSET_VALUE
|
||||||
@box = UNSET_VALUE
|
@box = UNSET_VALUE
|
||||||
|
@ignore_box_vagrantfile = UNSET_VALUE
|
||||||
@box_check_update = UNSET_VALUE
|
@box_check_update = UNSET_VALUE
|
||||||
@box_download_ca_cert = UNSET_VALUE
|
@box_download_ca_cert = UNSET_VALUE
|
||||||
@box_download_ca_path = UNSET_VALUE
|
@box_download_ca_path = UNSET_VALUE
|
||||||
|
@ -377,6 +379,7 @@ module VagrantPlugins
|
||||||
@base_mac = nil if @base_mac == UNSET_VALUE
|
@base_mac = nil if @base_mac == UNSET_VALUE
|
||||||
@boot_timeout = 300 if @boot_timeout == UNSET_VALUE
|
@boot_timeout = 300 if @boot_timeout == UNSET_VALUE
|
||||||
@box = nil if @box == UNSET_VALUE
|
@box = nil if @box == UNSET_VALUE
|
||||||
|
@ignore_box_vagrantfile = false if @ignore_box_vagrantfile == UNSET_VALUE
|
||||||
|
|
||||||
if @box_check_update == UNSET_VALUE
|
if @box_check_update == UNSET_VALUE
|
||||||
@box_check_update = !present?(ENV["VAGRANT_BOX_UPDATE_CHECK_DISABLE"])
|
@box_check_update = !present?(ENV["VAGRANT_BOX_UPDATE_CHECK_DISABLE"])
|
||||||
|
|
|
@ -208,6 +208,31 @@ describe Vagrant::Vagrantfile do
|
||||||
expect(box.name).to eq("base")
|
expect(box.name).to eq("base")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "does not configure box configuration if set to ignore" do
|
||||||
|
register_provider("foo")
|
||||||
|
|
||||||
|
configure do |config|
|
||||||
|
config.vm.box = "base"
|
||||||
|
config.vm.ignore_box_vagrantfile = true
|
||||||
|
end
|
||||||
|
|
||||||
|
iso_env.box3("base", "1.0", :foo, vagrantfile: <<-VF)
|
||||||
|
Vagrant.configure("2") do |config|
|
||||||
|
config.ssh.port = 123
|
||||||
|
config.vm.hostname = "hello"
|
||||||
|
end
|
||||||
|
VF
|
||||||
|
|
||||||
|
results = subject.machine_config(:default, :foo, boxes)
|
||||||
|
box = results[:box]
|
||||||
|
config = results[:config]
|
||||||
|
expect(config.vm.box).to eq("base")
|
||||||
|
expect(config.ssh.port).to eq(nil)
|
||||||
|
expect(config.vm.hostname).to eq(nil)
|
||||||
|
expect(box).to_not be_nil
|
||||||
|
expect(box.name).to eq("base")
|
||||||
|
end
|
||||||
|
|
||||||
it "configures with the proper box version" do
|
it "configures with the proper box version" do
|
||||||
register_provider("foo")
|
register_provider("foo")
|
||||||
|
|
||||||
|
|
|
@ -138,6 +138,11 @@ on the guest with the configured hostname.
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
|
`config.vm.ignore_box_vagrantfile` - If true, Vagrant will not load the the
|
||||||
|
settings found inside a boxes Vagrantfile, if present. Defaults to `false`.
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
||||||
`config.vm.network` - Configures [networks](/docs/networking/) on
|
`config.vm.network` - Configures [networks](/docs/networking/) on
|
||||||
the machine. Please see the networking page for more information.
|
the machine. Please see the networking page for more information.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue