diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index b842534b8..8260cd012 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -336,6 +336,7 @@ module Vagrant # Set this variable in order to keep track of if the box changes # too many times. original_box = config.vm.box + box_changed = false load_box_and_overrides = lambda do # If a box was found, then we attempt to load the Vagrantfile for @@ -366,11 +367,17 @@ module Vagrant end if config.vm.box && original_box != config.vm.box + if box_changed + # We already changed boxes once, so report an error that a + # box is attempting to change boxes again. + raise Errors::BoxConfigChangingBox + end + # The box changed, probably due to the provider override. Let's # run the configuration one more time with the new box. - # TODO: previous original box @logger.info("Box changed to: #{config.vm.box}. Reloading configurations.") original_box = config.vm.box + box_changed = true box = find_box(config.vm.box, box_formats) # Recurse so that we reload all the configurations diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index 1fbfd4c3f..1377464bb 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -103,6 +103,10 @@ module Vagrant error_key(:already_exists, "vagrant.actions.box.unpackage") end + class BoxConfigChangingBox < VagrantError + error_key(:box_config_changing_box) + end + class BoxMetadataFileNotFound < VagrantError error_key(:box_metadata_file_not_found) end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 6e76308c8..999336f47 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -120,6 +120,11 @@ en: Any errors that occurred are shown below. %{message} + box_config_changing_box: |- + While loading the Vagrantfile, the provider override specified + a new box. This box, in turn, specified a different box. This isn't + allowed, as it could lead to infinite recursion of Vagrant configuration + loading. Please fix this. box_metadata_file_not_found: |- The "metadata.json" file for the box '%{name}' was not found. Boxes require this file in order for Vagrant to determine the