From 4afbaa6f7042eb1cccc8938ee1ccb53c662ba41c Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Sat, 17 Nov 2007 11:40:15 +0100 Subject: fix #903: add patch from hrvojehr this moves logging of the command in front of failing from unexpected return. This helps very much to debug exec failures. Additionally I removed the unused local variable "loglevel" --- lib/puppet/type/exec.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/puppet/type/exec.rb b/lib/puppet/type/exec.rb index 9aab4dbd7..b76426495 100755 --- a/lib/puppet/type/exec.rb +++ b/lib/puppet/type/exec.rb @@ -113,12 +113,6 @@ module Puppet self.fail "Command exceeded timeout" % value.inspect end - loglevel = @resource[:loglevel] - if status.exitstatus.to_s != self.should.to_s - self.fail("%s returned %s instead of %s" % - [self.resource[:command], status.exitstatus, self.should.to_s]) - end - if log = @resource[:logoutput] if log == :true log = @resource[:loglevel] @@ -130,6 +124,11 @@ module Puppet end end + if status.exitstatus.to_s != self.should.to_s + self.fail("%s returned %s instead of %s" % + [self.resource[:command], status.exitstatus, self.should.to_s]) + end + return event end end -- cgit From 1b78f57284a37e86db2351c34a2bbf22c43f0275 Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Mon, 19 Nov 2007 10:21:56 +0100 Subject: Add Exec{ logoutput=> on_failure } This option only writes the output of the command to the log if the command failed. --- lib/puppet/type/exec.rb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/puppet/type/exec.rb b/lib/puppet/type/exec.rb index b76426495..5bb3158c4 100755 --- a/lib/puppet/type/exec.rb +++ b/lib/puppet/type/exec.rb @@ -114,8 +114,15 @@ module Puppet end if log = @resource[:logoutput] - if log == :true + case log + when :true log = @resource[:loglevel] + when :on_failure + if status.exitstatus.to_s != self.should.to_s + log = @resource[:loglevel] + else + log = :false + end end unless log == :false @output.split(/\n/).each { |line| @@ -200,10 +207,11 @@ module Puppet newparam(:logoutput) do desc "Whether to log output. Defaults to logging output at the - loglevel for the ``exec`` resource. Values are **true**, *false*, - and any legal log level." + loglevel for the ``exec`` resource. Use *on_failure* to only + log the output when the command reports an error. Values are + **true**, *false*, *on_failure*, and any legal log level." - values = [:true, :false] + values = [:true, :false, :on_failure] # And all of the log levels Puppet::Util::Log.eachlevel { |level| values << level } newvalues(*values) -- cgit