From 7a73f5bd7cac1ffec748936905e7caddc4c372b1 Mon Sep 17 00:00:00 2001 From: Eris Belew Date: Tue, 23 Sep 2014 12:46:25 -0700 Subject: [PATCH] Update shell provisioner for powershell to add "shell_args", saner defaults and more useful detail in logging output; Add Eclipse .project file to .gitignore IDE section --- .gitignore | 1 + plugins/provisioners/shell/config.rb | 3 +++ plugins/provisioners/shell/provisioner.rb | 16 ++++++++++++---- templates/locales/en.yml | 1 + 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 225e014d6..47b95a67e 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,7 @@ doc/ # IDE junk .idea/* *.iml +.project # Ruby Managers .rbenv diff --git a/plugins/provisioners/shell/config.rb b/plugins/provisioners/shell/config.rb index fbb7c812e..f69f8b731 100644 --- a/plugins/provisioners/shell/config.rb +++ b/plugins/provisioners/shell/config.rb @@ -10,6 +10,7 @@ module VagrantPlugins attr_accessor :privileged attr_accessor :binary attr_accessor :keep_color + attr_accessor :shell_args def initialize @args = UNSET_VALUE @@ -19,6 +20,7 @@ module VagrantPlugins @privileged = UNSET_VALUE @binary = UNSET_VALUE @keep_color = UNSET_VALUE + @shell_args = UNSET_VALUE end def finalize! @@ -29,6 +31,7 @@ module VagrantPlugins @privileged = true if @privileged == UNSET_VALUE @binary = false if @binary == UNSET_VALUE @keep_color = false if @keep_color == UNSET_VALUE + @shell_args = "-ExecutionPolicy Bypass" if @shell_args == UNSET_VALUE if @args && args_valid? @args = @args.is_a?(Array) ? @args.map { |a| a.to_s } : @args.to_s diff --git a/plugins/provisioners/shell/provisioner.rb b/plugins/provisioners/shell/provisioner.rb index 674c9c5fb..5aa19c401 100644 --- a/plugins/provisioners/shell/provisioner.rb +++ b/plugins/provisioners/shell/provisioner.rb @@ -100,14 +100,22 @@ module VagrantPlugins exec_path.gsub!('/', '\\') exec_path = "c:#{exec_path}" if exec_path.start_with?("\\") - # For PowerShell scripts bypass the execution policy + # Copy shell_args from configuration + shell_args = config.shell_args + + # For PowerShell scripts bypass the execution policy unless already specified + shell_args += " -ExecutionPolicy Bypass" if config.shell_args !~ /[-\/]ExecutionPolicy/i + + # CLIXML output is kinda useless, especially on non-windows hosts + shell_args += " -OutputFormat Text" if config.shell_args !~ /[-\/]OutputFormat/i + command = "#{exec_path}#{args}" - command = "powershell -executionpolicy bypass -file #{command}" if + command = "powershell #{shell_args.to_s} -file #{command}" if File.extname(exec_path).downcase == '.ps1' if config.path - @machine.ui.detail(I18n.t("vagrant.provisioners.shell.running", - script: exec_path)) + @machine.ui.detail(I18n.t("vagrant.provisioners.shell.runningas", + local: config.path.to_s, remote: exec_path)) else @machine.ui.detail(I18n.t("vagrant.provisioners.shell.running", script: "inline PowerShell script")) diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 4be7a92e7..a2055ae6f 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -1773,6 +1773,7 @@ en: path_and_inline_set: "Only one of `path` or `inline` may be set." path_invalid: "`path` for shell provisioner does not exist on the host system: %{path}" running: "Running: %{script}" + runningas: "Running: %{local} as %{remote}" upload_path_not_set: "`upload_path` must be set for the shell provisioner." ansible: