core: vagrant provision triggers sentinel creation [GH-4393]
This commit is contained in:
parent
bf75dc16e4
commit
d1d8ce7d52
|
@ -43,6 +43,8 @@ BUG FIXES:
|
||||||
- core: Use "-f" to `rm` files in case pty is true. [GH-4410]
|
- 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
|
- core: SSH key doesn't have to be owned by our user if we're running
|
||||||
as root. [GH-4387]
|
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/package: base package won't crash with exception [GH-4017]
|
||||||
- commands/rsync-auto: Destroyed machines won't raise exceptions. [GH-4031]
|
- commands/rsync-auto: Destroyed machines won't raise exceptions. [GH-4031]
|
||||||
- communicators/ssh: Nicer error if remote unexpectedly disconects. [GH-4038]
|
- communicators/ssh: Nicer error if remote unexpectedly disconects. [GH-4038]
|
||||||
|
|
|
@ -27,49 +27,49 @@ module Vagrant
|
||||||
config_enabled = env[:provision_enabled] if env.has_key?(:provision_enabled)
|
config_enabled = env[:provision_enabled] if env.has_key?(:provision_enabled)
|
||||||
|
|
||||||
# Check if we already provisioned, and if so, disable the rest
|
# Check if we already provisioned, and if so, disable the rest
|
||||||
sentinel_enabled = true
|
provision_enabled = true
|
||||||
|
|
||||||
ignore_sentinel = true
|
ignore_sentinel = true
|
||||||
if env.has_key?(:provision_ignore_sentinel)
|
if env.has_key?(:provision_ignore_sentinel)
|
||||||
ignore_sentinel = env[:provision_ignore_sentinel]
|
ignore_sentinel = env[:provision_ignore_sentinel]
|
||||||
end
|
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
|
update_sentinel = false
|
||||||
if !ignore_sentinel
|
if sentinel_path.file?
|
||||||
@logger.info("Checking provisioner sentinel if we should run...")
|
# The sentinel file is in the format of "version:data" so that
|
||||||
sentinel_path = env[:machine].data_dir.join("action_provision")
|
# we can remain backwards compatible with previous sentinels.
|
||||||
if sentinel_path.file?
|
# Versions so far:
|
||||||
# The sentinel file is in the format of "version:data" so that
|
#
|
||||||
# we can remain backwards compatible with previous sentinels.
|
# Vagrant < 1.5.0: A timestamp. The weakness here was that
|
||||||
# Versions so far:
|
# if it wasn't cleaned up, it would incorrectly not provision
|
||||||
#
|
# new machines.
|
||||||
# Vagrant < 1.5.0: A timestamp. The weakness here was that
|
#
|
||||||
# if it wasn't cleaned up, it would incorrectly not provision
|
# Vagrant >= 1.5.0: "1.5:ID", where ID is the machine ID.
|
||||||
# new machines.
|
# We compare both so we know whether it is a new machine.
|
||||||
#
|
#
|
||||||
# Vagrant >= 1.5.0: "1.5:ID", where ID is the machine ID.
|
contents = sentinel_path.read.chomp
|
||||||
# We compare both so we know whether it is a new machine.
|
parts = contents.split(":", 2)
|
||||||
#
|
|
||||||
contents = sentinel_path.read.chomp
|
|
||||||
parts = contents.split(":", 2)
|
|
||||||
|
|
||||||
if parts.length == 1
|
if parts.length == 1
|
||||||
@logger.info("Old-style sentinel found! Not provisioning.")
|
@logger.info("Old-style sentinel found! Not provisioning.")
|
||||||
sentinel_enabled = false
|
provision_enabled = false if !ignore_sentinel
|
||||||
update_sentinel = true
|
update_sentinel = true
|
||||||
elsif parts[0] == "1.5" && parts[1] == env[:machine].id.to_s
|
elsif parts[0] == "1.5" && parts[1] == env[:machine].id.to_s
|
||||||
@logger.info("Sentinel found! Not provisioning.")
|
@logger.info("Sentinel found! Not provisioning.")
|
||||||
sentinel_enabled = false
|
provision_enabled = false if !ignore_sentinel
|
||||||
else
|
else
|
||||||
@logger.info("Sentinel found with another machine ID. Removing.")
|
@logger.info("Sentinel found with another machine ID. Removing.")
|
||||||
sentinel_path.unlink
|
sentinel_path.unlink
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Store the value so that other actions can use it
|
# 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
|
# Ask the provisioners to modify the configuration if needed
|
||||||
provisioner_instances(env).each do |p, _|
|
provisioner_instances(env).each do |p, _|
|
||||||
|
@ -79,16 +79,6 @@ module Vagrant
|
||||||
# Continue, we need the VM to be booted.
|
# Continue, we need the VM to be booted.
|
||||||
@app.call(env)
|
@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 we're configured to not provision, notify the user and stop
|
||||||
if !config_enabled
|
if !config_enabled
|
||||||
env[:ui].info(I18n.t("vagrant.actions.vm.provision.disabled_by_config"))
|
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
|
# If we're not provisioning because of the sentinel, tell the user
|
||||||
# but continue trying for the "always" provisioners
|
# 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"))
|
env[:ui].info(I18n.t("vagrant.actions.vm.provision.disabled_by_sentinel"))
|
||||||
end
|
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)
|
type_map = provisioner_type_map(env)
|
||||||
provisioner_instances(env).each do |p, options|
|
provisioner_instances(env).each do |p, options|
|
||||||
type_name = type_map[p]
|
type_name = type_map[p]
|
||||||
|
@ -108,7 +106,7 @@ module Vagrant
|
||||||
!env[:provision_types].include?(type_name)
|
!env[:provision_types].include?(type_name)
|
||||||
|
|
||||||
# Don't run if sentinel is around and we're not always running
|
# 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(
|
env[:ui].info(I18n.t(
|
||||||
"vagrant.actions.vm.provision.beginning",
|
"vagrant.actions.vm.provision.beginning",
|
||||||
|
|
Loading…
Reference in New Issue