First pass at integrating new WinRM elevated execution wrapper
- Removed a lot of the Windows special casing from Chef runs - Don't attempt to use @config.binary_env since we don't properly pass this along to Chef
This commit is contained in:
parent
30b0399431
commit
99ce95198b
|
@ -1,82 +1,32 @@
|
||||||
require "tempfile"
|
|
||||||
|
|
||||||
require "vagrant/util/template_renderer"
|
|
||||||
|
|
||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
module Chef
|
module Chef
|
||||||
class CommandBuilderWindows < CommandBuilder
|
class CommandBuilderWindows < CommandBuilder
|
||||||
def build_command
|
def build_command
|
||||||
binary_path = "chef-#{@client_type}"
|
"#{chef_binary_path} #{chef_arguments}"
|
||||||
if @config.binary_path
|
|
||||||
binary_path = File.join(@config.binary_path, binary_path)
|
|
||||||
binary_path.gsub!("/", "\\")
|
|
||||||
binary_path = "c:#{binary_path}" if binary_path.start_with?("\\")
|
|
||||||
end
|
|
||||||
|
|
||||||
chef_arguments = "-c #{provisioning_path("#{@client_type}.rb")}"
|
|
||||||
chef_arguments << " -j #{provisioning_path("dna.json")}"
|
|
||||||
chef_arguments << " #{@config.arguments}" if @config.arguments
|
|
||||||
|
|
||||||
command_env = ""
|
|
||||||
command_env = "#{@config.binary_env} " if @config.binary_env
|
|
||||||
|
|
||||||
task_ps1_path = provisioning_path("cheftask.ps1")
|
|
||||||
|
|
||||||
opts = {
|
|
||||||
user: @machine.config.winrm.username,
|
|
||||||
pass: @machine.config.winrm.password,
|
|
||||||
chef_arguments: chef_arguments,
|
|
||||||
chef_binary_path: "#{command_env}#{binary_path}",
|
|
||||||
chef_stdout_log: provisioning_path("chef-#{@client_type}.log"),
|
|
||||||
chef_stderr_log: provisioning_path("chef-#{@client_type}.err.log"),
|
|
||||||
chef_task_exitcode: provisioning_path('cheftask.exitcode'),
|
|
||||||
chef_task_running: provisioning_path('cheftask.running'),
|
|
||||||
chef_task_ps1: task_ps1_path,
|
|
||||||
chef_task_run_ps1: provisioning_path('cheftaskrun.ps1'),
|
|
||||||
chef_task_xml: provisioning_path('cheftask.xml'),
|
|
||||||
}
|
|
||||||
|
|
||||||
# Upload the files we'll need
|
|
||||||
render_and_upload(
|
|
||||||
"cheftaskrun.ps1", opts[:chef_task_run_ps1], opts)
|
|
||||||
render_and_upload(
|
|
||||||
"cheftask.xml", opts[:chef_task_xml], opts)
|
|
||||||
render_and_upload(
|
|
||||||
"cheftask.ps1", opts[:chef_task_ps1], opts)
|
|
||||||
|
|
||||||
return <<-EOH
|
|
||||||
$old = Get-ExecutionPolicy;
|
|
||||||
Set-ExecutionPolicy Unrestricted -force;
|
|
||||||
#{task_ps1_path};
|
|
||||||
Set-ExecutionPolicy $old -force
|
|
||||||
EOH
|
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def provisioning_path(file)
|
def chef_binary_path
|
||||||
path = "#{@config.provisioning_path}/#{file}"
|
binary_path = "chef-#{@client_type}"
|
||||||
path.gsub!("/", "\\")
|
binary_path = win_path(File.join(@config.binary_path, binary_path)) if @config.binary_path
|
||||||
path = "c:#{path}" if path.start_with?("\\")
|
binary_path
|
||||||
path
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_and_upload(template, dest, opts)
|
def chef_arguments
|
||||||
path = File.expand_path("../scripts/#{template}", __FILE__)
|
chef_arguments = "-c #{provisioning_path("#{@client_type}.rb")}"
|
||||||
data = Vagrant::Util::TemplateRenderer.render(path, options)
|
chef_arguments << " -j #{provisioning_path("dna.json")}"
|
||||||
|
chef_arguments << " #{@config.arguments}" if @config.arguments
|
||||||
|
chef_arguments.strip
|
||||||
|
end
|
||||||
|
|
||||||
file = Tempfile.new("vagrant-chef")
|
def provisioning_path(file)
|
||||||
file.binmode
|
win_path(File.join(@config.provisioning_path, file))
|
||||||
file.write(data)
|
end
|
||||||
file.fsync
|
|
||||||
file.close
|
|
||||||
|
|
||||||
@machine.communicate.upload(file.path, dest)
|
def win_path(path)
|
||||||
ensure
|
path.gsub!("/", "\\")
|
||||||
if file
|
"c:#{path}" if path.start_with?("\\")
|
||||||
file.close
|
|
||||||
file.unlink
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -75,7 +75,8 @@ module VagrantPlugins
|
||||||
@machine.ui.info I18n.t("vagrant.provisioners.chef.running_client_again")
|
@machine.ui.info I18n.t("vagrant.provisioners.chef.running_client_again")
|
||||||
end
|
end
|
||||||
|
|
||||||
exit_status = @machine.communicate.sudo(command, :error_check => false) do |type, data|
|
opts = { error_check: false, elevated: true }
|
||||||
|
exit_status = @machine.communicate.sudo(command, opts) do |type, data|
|
||||||
# Output the data with the proper color based on the stream.
|
# Output the data with the proper color based on the stream.
|
||||||
color = type == :stdout ? :green : :red
|
color = type == :stdout ? :green : :red
|
||||||
|
|
||||||
|
|
|
@ -151,7 +151,8 @@ module VagrantPlugins
|
||||||
@machine.ui.info I18n.t("vagrant.provisioners.chef.running_solo_again")
|
@machine.ui.info I18n.t("vagrant.provisioners.chef.running_solo_again")
|
||||||
end
|
end
|
||||||
|
|
||||||
exit_status = @machine.communicate.sudo(command, :error_check => false) do |type, data|
|
opts = { error_check: false, elevated: true }
|
||||||
|
exit_status = @machine.communicate.sudo(command, opts) do |type, data|
|
||||||
# Output the data with the proper color based on the stream.
|
# Output the data with the proper color based on the stream.
|
||||||
color = type == :stdout ? :green : :red
|
color = type == :stdout ? :green : :red
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue