Class: VagrantPlugins::Shell::Provisioner

Inherits:
Object
  • Object
show all
Includes:
VagrantWindows::Helper
Defined in:
lib/vagrant-windows/monkey_patches/provisioner.rb

Instance Method Summary collapse

Methods included from VagrantWindows::Helper

#win_friendly_path

Instance Method Details

#provision_on_windowsObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/vagrant-windows/monkey_patches/provisioner.rb', line 17

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|
      # Ensure the uploaded script has a file extension, by default
      # config.upload_path from vagrant core does not
      fixed_upload_path = if File.extname(config.upload_path) == ""
        "#{config.upload_path}#{File.extname(path.to_s)}"
      else
        config.upload_path
      end
      comm.upload(path.to_s, fixed_upload_path)

      command = <<-EOH
      $old = Get-ExecutionPolicy;
      Set-ExecutionPolicy Unrestricted -force;
      #{win_friendly_path(fixed_upload_path)}#{args};
      Set-ExecutionPolicy $old -force
      EOH
      
      # 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