Skip to content

Commit

Permalink
fix uploads and use one shell for the entire provision
Browse files Browse the repository at this point in the history
  • Loading branch information
mwrock committed Sep 3, 2016
1 parent 11525e6 commit 3bd7a66
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
7 changes: 3 additions & 4 deletions lib/chef/provisioning/convergence_strategy/install_msi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ def setup_convergence(action_handler, machine)

action_handler.open_stream(machine.node['name']) do |stdout|
action_handler.open_stream(machine.node['name']) do |stderr|
machine.execute(action_handler, "powershell.exe -ExecutionPolicy Unrestricted -NoProfile \"& \"\"#{convergence_options[:install_script_path]}\"\"\"",
:raw => true,
machine.execute(action_handler, "& \"#{convergence_options[:install_script_path]}\"",
:stream_stdout => stdout,
:stream_stderr => stderr)
end
Expand All @@ -54,10 +53,10 @@ def converge(action_handler, machine)

action_handler.open_stream(machine.node['name']) do |stdout|
action_handler.open_stream(machine.node['name']) do |stderr|
command_line = "chef-client"
command_line = "$env:path = [System.Environment]::GetEnvironmentVariable('PATH', 'MACHINE');"
command_line << "chef-client"
command_line << " -l #{config[:log_level].to_s}" if config[:log_level]
machine.execute(action_handler, command_line,
:raw => true,
:stream_stdout => stdout,
:stream_stderr => stderr,
:timeout => @chef_client_timeout)
Expand Down
11 changes: 5 additions & 6 deletions lib/chef/provisioning/transport/winrm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def initialize(endpoint, type, options, global_config)
@options = options
@options[:endpoint] = endpoint
@options[:transport] = type
@options[:password] = @options[:password] || @options[:pass]
@config = global_config
end

Expand All @@ -33,10 +34,8 @@ def initialize(endpoint, type, options, global_config)

def execute(command, execute_options = {})
output = with_execute_timeout(execute_options) do
shell_type = execute_options[:raw] ? :cmd : :powershell
shell = session.shell(shell_type)
block = Proc.new { |stdout, stderr| stream_chunk(execute_options, stdout, stderr) }
shell.run(command, &block)
session.run(command, &block)
end
WinRMResult.new(command, execute_options, config, output)
end
Expand All @@ -54,9 +53,9 @@ def write_file(path, content)
file = Tempfile.new('provisioning-upload')
begin
file.write(content)
file_transporter.upload(file, path)
ensure
file.close
file_transporter.upload(file.path, path)
ensure
file.unlink # deletes the temp file
end
end
Expand Down Expand Up @@ -97,7 +96,7 @@ def make_url_available_to_remote(local_url)
def session
@session ||= begin
require 'winrm'
::WinRM::Connection.new(options)
::WinRM::Connection.new(options).shell(:powershell)
end
end

Expand Down

0 comments on commit 3bd7a66

Please sign in to comment.