Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix windows shell provisioner #45

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ GIT
PATH
remote: .
specs:
vagrant-windows (1.0.1)
vagrant-windows (1.0.2)
highline
winrm (~> 1.1.1)

Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-windows/communication/winrmcommunicator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def upload(from, to)
Base64.encode64(IO.binread(from)).gsub("\n",'').chars.to_a.each_slice(8000-file_name.size) do |chunk|
out = session.cmd( "echo #{chunk.join} >> \"#{file_name}\"" )
end
execute "mkdir [System.IO.Path]::GetDirectoryName(\"#{to}\")"
execute "mkdir $([System.IO.Path]::GetDirectoryName(\"#{to}\"))"
execute <<-EOH
$base64_string = Get-Content \"#{file_name}\"
$bytes = [System.Convert]::FromBase64String($base64_string)
Expand Down
51 changes: 51 additions & 0 deletions lib/vagrant-windows/monkey_patches/provisioner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require "#{VagrantWindows::vagrant_root}/plugins/provisioners/shell/provisioner"

module VagrantPlugins
module Shell
class Provisioner < Vagrant.plugin("2", :provisioner)

# This patch is needed until Vagrant supports Puppet on Windows guests
provision_on_linux = instance_method(:provision)

define_method(:provision) do
is_windows ? provision_on_windows() : provision_on_linux.bind(self).()
end

def provision_on_windows
args = ""
args = " #{config.args}" if config.args

with_script_file do |path|
# Upload the script to the machine
@machine.communicate.tap do |comm|
# Do the best effor to found what type of script or file is
# to set ot the upload_path
ext = File.extname(path.to_s)
fixed_upload_path = "#{config.upload_path}#{ext}"
comm.upload(path.to_s, fixed_upload_path)

execution_upload_path = "#{fixed_upload_path}".gsub('/','\\')
command = "$old = Get-ExecutionPolicy;Set-ExecutionPolicy Unrestricted -force;#{execution_upload_path}#{args};Set-ExecutionPolicy $old -force"
# Execute it with sudo
comm.sudo(command) do |type, data|
if [:stderr, :stdout].include?(type)
# Output the data with the proper color based on the stream.
color = type == :stdout ? :green : :red

# Note: Be sure to chomp the data to avoid the newlines that the
# Chef outputs.
@machine.env.ui.info(data.chomp, :color => color, :prefix => false)
end
end
end
end
end


def is_windows
@machine.config.vm.guest.eql? :windows
end

end # Provisioner class
end
end
5 changes: 4 additions & 1 deletion lib/vagrant-windows/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# Add Vagrant WinRM communication channel
require "vagrant-windows/communication/winrmcommunicator"

# Monkey patch the Puppet provisioner to support PowerShell/Windows
# Monkey patch the vbox42 driver
require "vagrant-windows/monkey_patches/vbox_42_driver"

# Monkey Patch the VM object to support multiple channels, i.e. WinRM
Expand All @@ -28,6 +28,9 @@
# Monkey patch the Chef-Solo provisioner to support PowerShell/Windows
require "vagrant-windows/monkey_patches/chef_solo"

# Monkey patch the shell provisioner to support PowerShell/batch/exe/Windows/etc
require "vagrant-windows/monkey_patches/provisioner"

# Add our windows specific config object
require "vagrant-windows/config/windows"

Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-windows/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module VagrantWindows
VERSION = "1.0.2"
VERSION = "1.0.3"
end