Merge pull request #5669 from taliesins/ChefProviderWindowsSupport

Use powershell syntax for Chef provisioner when using windows guest
This commit is contained in:
Seth Vargo 2015-05-30 21:31:43 -07:00
commit 01ce48ea9e
5 changed files with 70 additions and 9 deletions

View File

@ -0,0 +1,20 @@
module VagrantPlugins
module Chef
module Cap
module Windows
module ChefInstalled
# Check if Chef is installed at the given version.
# @return [true, false]
def self.chef_installed(machine, version)
if version != :latest
command = 'if ((&knife --version) -Match "Chef: "' + version + '"){ exit 0 } else { exit 1 }'
else
command = 'if ((&knife --version) -Match "Chef: *"){ exit 0 } else { exit 1 }'
end
machine.communicate.test(command, sudo: true)
end
end
end
end
end
end

View File

@ -58,6 +58,11 @@ module VagrantPlugins
Cap::Linux::ChefInstalled
end
guest_capability(:windows, :chef_installed) do
require_relative "cap/windows/chef_installed"
Cap::Windows::ChefInstalled
end
guest_capability(:debian, :chef_install) do
require_relative "cap/debian/chef_install"
Cap::Debian::ChefInstall

View File

@ -37,8 +37,14 @@ module VagrantPlugins
def verify_binary(binary)
# Checks for the existence of chef binary and error if it
# doesn't exist.
if windows?
command = "if ((&'#{binary}' -v) -Match 'Chef: *'){ exit 0 } else { exit 1 }"
else
command = "sh -c 'command -v #{binary}'"
end
@machine.communicate.sudo(
"sh -c 'command -v #{binary}'",
command,
error_class: ChefError,
error_key: :chef_not_detected,
binary: binary,
@ -66,11 +72,15 @@ module VagrantPlugins
@machine.communicate.tap do |comm|
paths.each do |path|
if windows?
comm.sudo("mkdir ""#{path}"" -f")
else
comm.sudo("mkdir -p #{path}")
comm.sudo("chown -h #{@machine.ssh_info[:username]} #{path}")
end
end
end
end
def setup_config(template, filename, template_vars)
# If we have custom configuration, upload it
@ -133,7 +143,13 @@ module VagrantPlugins
remote_file = File.join(@config.provisioning_path, "dna.json")
@machine.communicate.tap do |comm|
comm.sudo("rm -f #{remote_file}", error_check: false)
if windows?
command = "if (test-path '#{remote_file}') {rm '#{remote_file}' -force -recurse}"
else
command = "rm -f #{remote_file}"
end
comm.sudo(command, error_check: false)
comm.upload(temp.path, remote_file)
end
end
@ -146,7 +162,13 @@ module VagrantPlugins
"vagrant.provisioners.chef.upload_encrypted_data_bag_secret_key")
@machine.communicate.tap do |comm|
comm.sudo("rm -f #{remote_file}", error_check: false)
if windows?
command = "if (test-path ""#{remote_file}"") {rm ""#{remote_file}"" -force -recurse}"
else
command = "rm -f #{remote_file}"
end
comm.sudo(command, error_check: false)
comm.upload(encrypted_data_bag_secret_key_path, remote_file)
end
end
@ -154,7 +176,13 @@ module VagrantPlugins
def delete_encrypted_data_bag_secret
remote_file = guest_encrypted_data_bag_secret_key_path
if remote_file
@machine.communicate.sudo("rm -f #{remote_file}", error_check: false)
if windows?
command = "if (test-path ""#{remote_file}"") {rm ""#{remote_file}"" -force -recurse}"
else
command = "rm -f #{remote_file}"
end
@machine.communicate.sudo(command, error_check: false)
end
end

View File

@ -18,8 +18,12 @@ module VagrantPlugins
user = @machine.ssh_info[:username]
# Reset upload path permissions for the current ssh user
if windows?
@machine.communicate.sudo("mkdir ""#{config.upload_path}"" -f")
else
@machine.communicate.sudo("mkdir -p #{config.upload_path}")
@machine.communicate.sudo("chown -R #{user} #{config.upload_path}")
end
# Upload the recipe
upload_recipe

View File

@ -39,8 +39,12 @@ module VagrantPlugins
@machine.ui.info I18n.t("vagrant.provisioners.chef.client_key_folder")
path = Pathname.new(@config.client_key_path)
if windows?
@machine.communicate.sudo("mkdir ""#{path.dirname}"" -f")
else
@machine.communicate.sudo("mkdir -p #{path.dirname}")
end
end
def upload_validation_key
@machine.ui.info I18n.t("vagrant.provisioners.chef.upload_validation_key")