From 282c7341c94df336384a256cd1c4fa2def358436 Mon Sep 17 00:00:00 2001 From: Alex Wu Date: Tue, 10 Jan 2017 13:06:12 +0800 Subject: [PATCH 1/7] add a option to ignore the vagrantfile packaged with the box --- plugins/kernel_v2/config/vm.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/kernel_v2/config/vm.rb b/plugins/kernel_v2/config/vm.rb index 2214f42a5..1ff3c95bb 100644 --- a/plugins/kernel_v2/config/vm.rb +++ b/plugins/kernel_v2/config/vm.rb @@ -22,6 +22,7 @@ module VagrantPlugins attr_accessor :base_mac attr_accessor :boot_timeout attr_accessor :box + attr_accessor :box_ignore_box_vagrantfile attr_accessor :box_check_update attr_accessor :box_url attr_accessor :box_server_url @@ -51,6 +52,7 @@ module VagrantPlugins @base_mac = UNSET_VALUE @boot_timeout = UNSET_VALUE @box = UNSET_VALUE + @box_ignore_box_vagrantfile = UNSET_VALUE @box_check_update = UNSET_VALUE @box_download_ca_cert = UNSET_VALUE @box_download_ca_path = UNSET_VALUE @@ -378,6 +380,8 @@ module VagrantPlugins @boot_timeout = 300 if @boot_timeout == UNSET_VALUE @box = nil if @box == UNSET_VALUE + @box_ignore_box_vagrantfile = false if @box_ignore_box_vagrantfile == UNSET_VALUE + if @box_check_update == UNSET_VALUE @box_check_update = !present?(ENV["VAGRANT_BOX_UPDATE_CHECK_DISABLE"]) end From 710b8da9533c13f75c087dd243175777510a0fc2 Mon Sep 17 00:00:00 2001 From: Alex Wu Date: Tue, 10 Jan 2017 13:21:13 +0800 Subject: [PATCH 2/7] add config option 'box_ignore_box_vagrantfile' to ignore the Vagrantfile packaged in the box. --- lib/vagrant/vagrantfile.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vagrant/vagrantfile.rb b/lib/vagrant/vagrantfile.rb index 3f3c8c826..32bb06017 100644 --- a/lib/vagrant/vagrantfile.rb +++ b/lib/vagrant/vagrantfile.rb @@ -191,7 +191,7 @@ module Vagrant local_keys = keys.dup # Load the box Vagrantfile, if there is one - if config.vm.box && boxes + if config.vm.box && !config.vm.box_ignore_box_vagrantfile && boxes box = boxes.find(config.vm.box, box_formats, config.vm.box_version) if box box_vagrantfile = find_vagrantfile(box.directory) From a45e62cacdf25fc79e849527b5ca7b24e2532d1e Mon Sep 17 00:00:00 2001 From: Alex Wu Date: Tue, 10 Jan 2017 17:39:28 +0800 Subject: [PATCH 3/7] fix the import issue when 'box_ignore_box_vagrantfile' is set, the box object should never be null. --- lib/vagrant/vagrantfile.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/vagrant/vagrantfile.rb b/lib/vagrant/vagrantfile.rb index 32bb06017..7ee8a2d06 100644 --- a/lib/vagrant/vagrantfile.rb +++ b/lib/vagrant/vagrantfile.rb @@ -191,11 +191,11 @@ module Vagrant local_keys = keys.dup # Load the box Vagrantfile, if there is one - if config.vm.box && !config.vm.box_ignore_box_vagrantfile && boxes + if config.vm.box && boxes box = boxes.find(config.vm.box, box_formats, config.vm.box_version) if box box_vagrantfile = find_vagrantfile(box.directory) - if box_vagrantfile + if box_vagrantfile && !config.vm.box_ignore_box_vagrantfile box_config_key = "#{boxes.object_id}_#{box.name}_#{box.provider}".to_sym @loader.set(box_config_key, box_vagrantfile) From 424f49b9196540755107a93e18f303887a74f2c5 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Wed, 26 Sep 2018 10:31:41 -0700 Subject: [PATCH 4/7] Simplify config option to ignore box vagrantfile --- lib/vagrant/vagrantfile.rb | 2 +- plugins/kernel_v2/config/vm.rb | 7 +++---- website/source/docs/vagrantfile/machine_settings.html.md | 5 +++++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/vagrant/vagrantfile.rb b/lib/vagrant/vagrantfile.rb index 7ee8a2d06..5ac4bf987 100644 --- a/lib/vagrant/vagrantfile.rb +++ b/lib/vagrant/vagrantfile.rb @@ -195,7 +195,7 @@ module Vagrant box = boxes.find(config.vm.box, box_formats, config.vm.box_version) if box box_vagrantfile = find_vagrantfile(box.directory) - if box_vagrantfile && !config.vm.box_ignore_box_vagrantfile + if box_vagrantfile && !config.vm.ignore_box_vagrantfile box_config_key = "#{boxes.object_id}_#{box.name}_#{box.provider}".to_sym @loader.set(box_config_key, box_vagrantfile) diff --git a/plugins/kernel_v2/config/vm.rb b/plugins/kernel_v2/config/vm.rb index 1ff3c95bb..6ed45729c 100644 --- a/plugins/kernel_v2/config/vm.rb +++ b/plugins/kernel_v2/config/vm.rb @@ -22,7 +22,7 @@ module VagrantPlugins attr_accessor :base_mac attr_accessor :boot_timeout attr_accessor :box - attr_accessor :box_ignore_box_vagrantfile + attr_accessor :ignore_box_vagrantfile attr_accessor :box_check_update attr_accessor :box_url attr_accessor :box_server_url @@ -52,7 +52,7 @@ module VagrantPlugins @base_mac = UNSET_VALUE @boot_timeout = UNSET_VALUE @box = UNSET_VALUE - @box_ignore_box_vagrantfile = UNSET_VALUE + @ignore_box_vagrantfile = UNSET_VALUE @box_check_update = UNSET_VALUE @box_download_ca_cert = UNSET_VALUE @box_download_ca_path = UNSET_VALUE @@ -379,8 +379,7 @@ module VagrantPlugins @base_mac = nil if @base_mac == UNSET_VALUE @boot_timeout = 300 if @boot_timeout == UNSET_VALUE @box = nil if @box == UNSET_VALUE - - @box_ignore_box_vagrantfile = false if @box_ignore_box_vagrantfile == UNSET_VALUE + @ignore_box_vagrantfile = false if @ignore_box_vagrantfile == UNSET_VALUE if @box_check_update == UNSET_VALUE @box_check_update = !present?(ENV["VAGRANT_BOX_UPDATE_CHECK_DISABLE"]) diff --git a/website/source/docs/vagrantfile/machine_settings.html.md b/website/source/docs/vagrantfile/machine_settings.html.md index 7d6fe9a19..2854e5c40 100644 --- a/website/source/docs/vagrantfile/machine_settings.html.md +++ b/website/source/docs/vagrantfile/machine_settings.html.md @@ -138,6 +138,11 @@ on the guest with the configured hostname.
+`config.vm.ignore_box_vagrantfile` - If true, Vagrant will not load the the +settings found inside a boxes Vagrantfile, if present. Defaults to `false`. + +
+ `config.vm.network` - Configures [networks](/docs/networking/) on the machine. Please see the networking page for more information. From f6ae32834605db98234ebaa0aa95182e77ff9e2d Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Wed, 26 Sep 2018 10:31:55 -0700 Subject: [PATCH 5/7] Add test for ignore_box_vagrantfile option --- test/unit/vagrant/vagrantfile_test.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/unit/vagrant/vagrantfile_test.rb b/test/unit/vagrant/vagrantfile_test.rb index f901413f4..39e783db7 100644 --- a/test/unit/vagrant/vagrantfile_test.rb +++ b/test/unit/vagrant/vagrantfile_test.rb @@ -208,6 +208,31 @@ describe Vagrant::Vagrantfile do expect(box.name).to eq("base") 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 register_provider("foo") From 5520cf65d6f27e4622efe9e4d24cc0caed222cf2 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Fri, 28 Sep 2018 16:44:50 -0700 Subject: [PATCH 6/7] Add warning if Vagrantfile inside box is ignored --- lib/vagrant/vagrantfile.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/vagrant/vagrantfile.rb b/lib/vagrant/vagrantfile.rb index 5ac4bf987..0c5f871e9 100644 --- a/lib/vagrant/vagrantfile.rb +++ b/lib/vagrant/vagrantfile.rb @@ -1,4 +1,5 @@ require "vagrant/util/template_renderer" +require "log4r" module Vagrant # This class provides a way to load and access the contents @@ -26,6 +27,7 @@ module Vagrant @keys = keys @loader = loader @config, _ = loader.load(keys) + @logger = Log4r::Logger.new("vagrant::vagrantfile") end # Returns a {Machine} for the given name and provider that @@ -201,6 +203,8 @@ module Vagrant @loader.set(box_config_key, box_vagrantfile) local_keys.unshift(box_config_key) config, config_warnings, config_errors = @loader.load(local_keys) + else + @logger.warn("Ignoring #{box.name} provided Vagrantfile inside box") end end end From 7798add2962314016aa155aea0822e0c59bdc193 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Fri, 28 Sep 2018 17:00:41 -0700 Subject: [PATCH 7/7] Ensure log is only printed if box has Vagrantfile --- lib/vagrant/vagrantfile.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vagrant/vagrantfile.rb b/lib/vagrant/vagrantfile.rb index 0c5f871e9..1bf64750e 100644 --- a/lib/vagrant/vagrantfile.rb +++ b/lib/vagrant/vagrantfile.rb @@ -203,7 +203,7 @@ module Vagrant @loader.set(box_config_key, box_vagrantfile) local_keys.unshift(box_config_key) config, config_warnings, config_errors = @loader.load(local_keys) - else + elsif box_vagrantfile && config.vm.ignore_box_vagrantfile @logger.warn("Ignoring #{box.name} provided Vagrantfile inside box") end end