core: when packaging, preserve generated key [GH-5780]

This commit is contained in:
Mitchell Hashimoto 2015-11-19 18:18:43 -08:00
parent 40336016e1
commit d3ab73cf4a
1 changed files with 16 additions and 1 deletions

View File

@ -113,6 +113,21 @@ module Vagrant
# If we don't have a generated private key, we do nothing
path = @env[:machine].data_dir.join("private_key")
if !path.file?
# If we have a private key that was copied into this box,
# then we copy that. This is a bit of a heuristic and can be a
# security risk if the key is named the correct thing, but
# we'll take that risk for dev environments.
(@env[:machine].config.ssh.private_key_path || []).each do |p|
# If we have the correctly named key, copy it
if File.basename(p) == "vagrant_private_key"
path = Pathname.new(p)
break
end
end
end
# If we still have no matching key, do nothing
return if !path.file?
# Copy it into our box directory