diff --git a/lib/vagrant/command/helpers.rb b/lib/vagrant/command/helpers.rb index 678faed5a..80eda6a27 100644 --- a/lib/vagrant/command/helpers.rb +++ b/lib/vagrant/command/helpers.rb @@ -28,6 +28,16 @@ module Vagrant [vm] end end + + # This will yield for each target VM to the command. The VM is guaranteed + # to be loaded on each iteration. + def with_target_vms + target_vms.each do |old_vm| + # We get a new VM here to avoid potentially stale VMs + vm = env.vms[old_vm.name] + yield vm + end + end end end end diff --git a/lib/vagrant/command/up.rb b/lib/vagrant/command/up.rb index fa81a0030..7ec6b5bc2 100644 --- a/lib/vagrant/command/up.rb +++ b/lib/vagrant/command/up.rb @@ -5,7 +5,7 @@ module Vagrant register "up", "Creates the Vagrant environment" def execute - target_vms.each do |vm| + with_target_vms do |vm| if vm.created? vm.env.ui.info I18n.t("vagrant.commands.up.vm_created") vm.start("provision.enabled" => options[:provision]) diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index 04fc67354..c9fe69a3a 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -357,11 +357,11 @@ module Vagrant # Reloads the configuration of this environment. def reload! - @config = nil - @vms = nil + # Reload the configuration load_config! - load_vms! - self + + # Clear the VMs because this can now be diferent due to configuration + @vms = nil end # Loads this environment's configuration and stores it in the {#config}