diff options
author | Jay Mundrawala <jdmundrawala@gmail.com> | 2014-08-22 14:49:53 -0700 |
---|---|---|
committer | Jay Mundrawala <jdmundrawala@gmail.com> | 2014-09-19 12:47:34 -0700 |
commit | 31f0e0a53d82d4cab7b607e367dec5ec6104847c (patch) | |
tree | 0e9125f44d2a004715261673878a055d2e8ef68a /lib/chef/util/powershell | |
parent | 7e5daa0ef8486275c82e694d1862d56b5a21f417 (diff) | |
download | chef-31f0e0a53d82d4cab7b607e367dec5ec6104847c.tar.gz |
Deal with LCM failing when a resource does not support WhatIf
Diffstat (limited to 'lib/chef/util/powershell')
-rw-r--r-- | lib/chef/util/powershell/cmdlet.rb | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/chef/util/powershell/cmdlet.rb b/lib/chef/util/powershell/cmdlet.rb index 71bd876e40..f99812dc24 100644 --- a/lib/chef/util/powershell/cmdlet.rb +++ b/lib/chef/util/powershell/cmdlet.rb @@ -25,7 +25,7 @@ class Chef::Util::Powershell def initialize(node, cmdlet, output_format=nil, output_format_options={}) @output_format = output_format @node = node - + case output_format when nil @json_format = false @@ -55,7 +55,7 @@ class Chef::Util::Powershell if @json_format && @output_format_options.has_key?(:depth) json_depth = @output_format_options[:depth] end - + json_command = @json_format ? " | convertto-json -compress -depth #{json_depth}" : "" command_string = "powershell.exe -executionpolicy bypass -noprofile -noninteractive -command \"trap [Exception] {write-error -exception ($_.Exception.Message);exit 1};#{@cmdlet} #{switches_string} #{arguments_string}#{json_command}\";if ( ! $? ) { exit 1 }" @@ -65,13 +65,17 @@ class Chef::Util::Powershell os_architecture = "#{ENV['PROCESSOR_ARCHITEW6432']}" == 'AMD64' ? :x86_64 : :i386 status = nil - + with_os_architecture(@node) do - status = command.run_command + status = command.run_command end - - result = CmdletResult.new(status, @output_format) - + + CmdletResult.new(status, @output_format) + end + + def run!(switches={}, execution_options={}, *arguments) + result = run(switches, execution_options, arguments) + if ! result.succeeded? raise Chef::Exceptions::PowershellCmdletException, "Powershell Cmdlet failed: #{result.stderr}" end |