From d1d8ce7d52514bfcc9584e815e9dabc5bbafa938 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 29 Aug 2014 10:26:44 -0700 Subject: [PATCH] core: vagrant provision triggers sentinel creation [GH-4393] --- CHANGELOG.md | 2 + lib/vagrant/action/builtin/provision.rb | 84 ++++++++++++------------- 2 files changed, 43 insertions(+), 43 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ecfcd31c6..e08723ce9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,8 @@ BUG FIXES: - core: Use "-f" to `rm` files in case pty is true. [GH-4410] - core: SSH key doesn't have to be owned by our user if we're running as root. [GH-4387] + - core: "vagrant provision" will cause "vagrant up" to properly not + reprovision. [GH-4393] - commands/package: base package won't crash with exception [GH-4017] - commands/rsync-auto: Destroyed machines won't raise exceptions. [GH-4031] - communicators/ssh: Nicer error if remote unexpectedly disconects. [GH-4038] diff --git a/lib/vagrant/action/builtin/provision.rb b/lib/vagrant/action/builtin/provision.rb index 494f9b94b..0795a2ddc 100644 --- a/lib/vagrant/action/builtin/provision.rb +++ b/lib/vagrant/action/builtin/provision.rb @@ -27,49 +27,49 @@ module Vagrant config_enabled = env[:provision_enabled] if env.has_key?(:provision_enabled) # Check if we already provisioned, and if so, disable the rest - sentinel_enabled = true + provision_enabled = true ignore_sentinel = true if env.has_key?(:provision_ignore_sentinel) ignore_sentinel = env[:provision_ignore_sentinel] end + if ignore_sentinel + @logger.info("Ignoring sentinel check, forcing provision") + end - sentinel_path = nil + @logger.info("Checking provisioner sentinel file...") + sentinel_path = env[:machine].data_dir.join("action_provision") update_sentinel = false - if !ignore_sentinel - @logger.info("Checking provisioner sentinel if we should run...") - sentinel_path = env[:machine].data_dir.join("action_provision") - if sentinel_path.file? - # The sentinel file is in the format of "version:data" so that - # we can remain backwards compatible with previous sentinels. - # Versions so far: - # - # Vagrant < 1.5.0: A timestamp. The weakness here was that - # if it wasn't cleaned up, it would incorrectly not provision - # new machines. - # - # Vagrant >= 1.5.0: "1.5:ID", where ID is the machine ID. - # We compare both so we know whether it is a new machine. - # - contents = sentinel_path.read.chomp - parts = contents.split(":", 2) + if sentinel_path.file? + # The sentinel file is in the format of "version:data" so that + # we can remain backwards compatible with previous sentinels. + # Versions so far: + # + # Vagrant < 1.5.0: A timestamp. The weakness here was that + # if it wasn't cleaned up, it would incorrectly not provision + # new machines. + # + # Vagrant >= 1.5.0: "1.5:ID", where ID is the machine ID. + # We compare both so we know whether it is a new machine. + # + contents = sentinel_path.read.chomp + parts = contents.split(":", 2) - if parts.length == 1 - @logger.info("Old-style sentinel found! Not provisioning.") - sentinel_enabled = false - update_sentinel = true - elsif parts[0] == "1.5" && parts[1] == env[:machine].id.to_s - @logger.info("Sentinel found! Not provisioning.") - sentinel_enabled = false - else - @logger.info("Sentinel found with another machine ID. Removing.") - sentinel_path.unlink - end + if parts.length == 1 + @logger.info("Old-style sentinel found! Not provisioning.") + provision_enabled = false if !ignore_sentinel + update_sentinel = true + elsif parts[0] == "1.5" && parts[1] == env[:machine].id.to_s + @logger.info("Sentinel found! Not provisioning.") + provision_enabled = false if !ignore_sentinel + else + @logger.info("Sentinel found with another machine ID. Removing.") + sentinel_path.unlink end end # Store the value so that other actions can use it - env[:provision_enabled] = sentinel_enabled if !env.has_key?(:provision_enabled) + env[:provision_enabled] = provision_enabled if !env.has_key?(:provision_enabled) # Ask the provisioners to modify the configuration if needed provisioner_instances(env).each do |p, _| @@ -79,16 +79,6 @@ module Vagrant # Continue, we need the VM to be booted. @app.call(env) - # Write the sentinel if we have to - if sentinel_path - if update_sentinel || !sentinel_path.file? - @logger.info("Writing provisioning sentinel so we don't provision again") - sentinel_path.open("w") do |f| - f.write("1.5:#{env[:machine].id}") - end - end - end - # If we're configured to not provision, notify the user and stop if !config_enabled env[:ui].info(I18n.t("vagrant.actions.vm.provision.disabled_by_config")) @@ -97,10 +87,18 @@ module Vagrant # If we're not provisioning because of the sentinel, tell the user # but continue trying for the "always" provisioners - if !sentinel_enabled + if !provision_enabled env[:ui].info(I18n.t("vagrant.actions.vm.provision.disabled_by_sentinel")) end + # Write the sentinel if we have to + if update_sentinel || !sentinel_path.file? + @logger.info("Writing provisioning sentinel so we don't provision again") + sentinel_path.open("w") do |f| + f.write("1.5:#{env[:machine].id}") + end + end + type_map = provisioner_type_map(env) provisioner_instances(env).each do |p, options| type_name = type_map[p] @@ -108,7 +106,7 @@ module Vagrant !env[:provision_types].include?(type_name) # Don't run if sentinel is around and we're not always running - next if !sentinel_enabled && options[:run] != :always + next if !provision_enabled && options[:run] != :always env[:ui].info(I18n.t( "vagrant.actions.vm.provision.beginning",