Merge pull request #5669 from taliesins/ChefProviderWindowsSupport
Use powershell syntax for Chef provisioner when using windows guest
This commit is contained in:
commit
01ce48ea9e
|
@ -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
|
|
@ -58,6 +58,11 @@ module VagrantPlugins
|
||||||
Cap::Linux::ChefInstalled
|
Cap::Linux::ChefInstalled
|
||||||
end
|
end
|
||||||
|
|
||||||
|
guest_capability(:windows, :chef_installed) do
|
||||||
|
require_relative "cap/windows/chef_installed"
|
||||||
|
Cap::Windows::ChefInstalled
|
||||||
|
end
|
||||||
|
|
||||||
guest_capability(:debian, :chef_install) do
|
guest_capability(:debian, :chef_install) do
|
||||||
require_relative "cap/debian/chef_install"
|
require_relative "cap/debian/chef_install"
|
||||||
Cap::Debian::ChefInstall
|
Cap::Debian::ChefInstall
|
||||||
|
|
|
@ -37,8 +37,14 @@ module VagrantPlugins
|
||||||
def verify_binary(binary)
|
def verify_binary(binary)
|
||||||
# Checks for the existence of chef binary and error if it
|
# Checks for the existence of chef binary and error if it
|
||||||
# doesn't exist.
|
# 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(
|
@machine.communicate.sudo(
|
||||||
"sh -c 'command -v #{binary}'",
|
command,
|
||||||
error_class: ChefError,
|
error_class: ChefError,
|
||||||
error_key: :chef_not_detected,
|
error_key: :chef_not_detected,
|
||||||
binary: binary,
|
binary: binary,
|
||||||
|
@ -66,11 +72,15 @@ module VagrantPlugins
|
||||||
|
|
||||||
@machine.communicate.tap do |comm|
|
@machine.communicate.tap do |comm|
|
||||||
paths.each do |path|
|
paths.each do |path|
|
||||||
|
if windows?
|
||||||
|
comm.sudo("mkdir ""#{path}"" -f")
|
||||||
|
else
|
||||||
comm.sudo("mkdir -p #{path}")
|
comm.sudo("mkdir -p #{path}")
|
||||||
comm.sudo("chown -h #{@machine.ssh_info[:username]} #{path}")
|
comm.sudo("chown -h #{@machine.ssh_info[:username]} #{path}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def setup_config(template, filename, template_vars)
|
def setup_config(template, filename, template_vars)
|
||||||
# If we have custom configuration, upload it
|
# If we have custom configuration, upload it
|
||||||
|
@ -133,7 +143,13 @@ module VagrantPlugins
|
||||||
|
|
||||||
remote_file = File.join(@config.provisioning_path, "dna.json")
|
remote_file = File.join(@config.provisioning_path, "dna.json")
|
||||||
@machine.communicate.tap do |comm|
|
@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)
|
comm.upload(temp.path, remote_file)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -146,7 +162,13 @@ module VagrantPlugins
|
||||||
"vagrant.provisioners.chef.upload_encrypted_data_bag_secret_key")
|
"vagrant.provisioners.chef.upload_encrypted_data_bag_secret_key")
|
||||||
|
|
||||||
@machine.communicate.tap do |comm|
|
@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)
|
comm.upload(encrypted_data_bag_secret_key_path, remote_file)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -154,7 +176,13 @@ module VagrantPlugins
|
||||||
def delete_encrypted_data_bag_secret
|
def delete_encrypted_data_bag_secret
|
||||||
remote_file = guest_encrypted_data_bag_secret_key_path
|
remote_file = guest_encrypted_data_bag_secret_key_path
|
||||||
if remote_file
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -18,8 +18,12 @@ module VagrantPlugins
|
||||||
user = @machine.ssh_info[:username]
|
user = @machine.ssh_info[:username]
|
||||||
|
|
||||||
# Reset upload path permissions for the current ssh user
|
# 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("mkdir -p #{config.upload_path}")
|
||||||
@machine.communicate.sudo("chown -R #{user} #{config.upload_path}")
|
@machine.communicate.sudo("chown -R #{user} #{config.upload_path}")
|
||||||
|
end
|
||||||
|
|
||||||
# Upload the recipe
|
# Upload the recipe
|
||||||
upload_recipe
|
upload_recipe
|
||||||
|
|
|
@ -39,8 +39,12 @@ module VagrantPlugins
|
||||||
@machine.ui.info I18n.t("vagrant.provisioners.chef.client_key_folder")
|
@machine.ui.info I18n.t("vagrant.provisioners.chef.client_key_folder")
|
||||||
path = Pathname.new(@config.client_key_path)
|
path = Pathname.new(@config.client_key_path)
|
||||||
|
|
||||||
|
if windows?
|
||||||
|
@machine.communicate.sudo("mkdir ""#{path.dirname}"" -f")
|
||||||
|
else
|
||||||
@machine.communicate.sudo("mkdir -p #{path.dirname}")
|
@machine.communicate.sudo("mkdir -p #{path.dirname}")
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def upload_validation_key
|
def upload_validation_key
|
||||||
@machine.ui.info I18n.t("vagrant.provisioners.chef.upload_validation_key")
|
@machine.ui.info I18n.t("vagrant.provisioners.chef.upload_validation_key")
|
||||||
|
|
Loading…
Reference in New Issue