diff options
author | adamedx <adamed@getchef.com> | 2015-05-22 23:07:16 -0700 |
---|---|---|
committer | adamedx <adamed@getchef.com> | 2015-05-23 14:20:19 -0700 |
commit | 9f242e2af3f32e413cf6fcfabe48d6ebdc03cd80 (patch) | |
tree | bb01bb11ede536824ff74be293d4d7fc394cad1b /lib/chef/provider/powershell_script.rb | |
parent | ac274bc53e30a09182ec4b13d4de9d6d639f422d (diff) | |
download | chef-adamedx/x-powershell-exitstatus.tar.gz |
Use executionpolicy Bypass in powershell_script provider for PS 3.0 and lateradamedx/x-powershell-exitstatus
Diffstat (limited to 'lib/chef/provider/powershell_script.rb')
-rw-r--r-- | lib/chef/provider/powershell_script.rb | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/chef/provider/powershell_script.rb b/lib/chef/provider/powershell_script.rb index 3b86e2a5de..ed44dee6ae 100644 --- a/lib/chef/provider/powershell_script.rb +++ b/lib/chef/provider/powershell_script.rb @@ -26,7 +26,7 @@ class Chef def initialize (new_resource, run_context) super(new_resource, run_context, '.ps1') - normalize_script_exit_status + add_exit_status_wrapper end def action_run @@ -53,7 +53,7 @@ class Chef # Process exit codes are strange with PowerShell and require # special handling to cover common use cases. - def normalize_script_exit_status + def add_exit_status_wrapper self.code = wrapper_script Chef::Log.debug("powershell_script provider called with script code:\n\n#{@new_resource.code}\n") Chef::Log.debug("powershell_script provider will execute transformed code:\n\n#{self.code}\n") @@ -82,11 +82,17 @@ class Chef end def default_interpreter_flags + # 'Bypass' is preferable since it doesn't require user input confirmation + # for files such as PowerShell modules downloaded from the + # Internet. However, 'Bypass' is not supported prior to + # PowerShell 3.0, so the fallback is 'Unrestricted' + execution_policy = Chef::Platform.supports_powershell_execution_bypass?(run_context.node) ? 'Bypass' : 'Unrestricted' + [ "-NoLogo", "-NonInteractive", "-NoProfile", - "-ExecutionPolicy Unrestricted", + "-ExecutionPolicy #{execution_policy}", # Powershell will hang if STDIN is redirected # http://connect.microsoft.com/PowerShell/feedback/details/572313/powershell-exe-can-hang-if-stdin-is-redirected "-InputFormat None" |