diff --git a/CHANGELOG.md b/CHANGELOG.md index 834829ed3..8f458b764 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ FEATURES: `vagrant destroy`. [GH-1302] - Chef Client provisioner will now clean up the node/client using `knife` if configured to do so. + - `vagrant up` has a `--no-destroy-on-error` flag that will not destroy + the VM if a fatal error occurs. [GH-2011] IMPROVEMENTS: diff --git a/plugins/commands/up/command.rb b/plugins/commands/up/command.rb index 480342ecd..5d5125882 100644 --- a/plugins/commands/up/command.rb +++ b/plugins/commands/up/command.rb @@ -11,6 +11,7 @@ module VagrantPlugins def execute options = {} + options[:destroy_on_error] = true options[:parallel] = true opts = OptionParser.new do |o| @@ -19,6 +20,11 @@ module VagrantPlugins build_start_options(o, options) + o.on("--[no-]destroy-on-error", + "Destroy machine if any fatal error happens (default to true).") do |destroy| + options[:destroy_on_error] = destroy + end + o.on("--[no-]parallel", "Enable or disable parallelism if provider supports it.") do |parallel| options[:parallel] = parallel diff --git a/plugins/providers/virtualbox/action/import.rb b/plugins/providers/virtualbox/action/import.rb index 14ac2b0bb..ce091bc6d 100644 --- a/plugins/providers/virtualbox/action/import.rb +++ b/plugins/providers/virtualbox/action/import.rb @@ -36,6 +36,9 @@ module VagrantPlugins if env[:machine].provider.state.id != :not_created return if env["vagrant.error"].is_a?(Vagrant::Errors::VagrantError) + # If we're not supposed to destroy on error then just return + return if !env[:destroy_on_error] + # Interrupted, destroy the VM. We note that we don't want to # validate the configuration here, and we don't want to confirm # we want to destroy.