Feature #5703

Print output from postrun_command and prerun_command

Added by Paul Berry over 2 years ago. Updated over 1 year ago.

Status:In Topic Branch Pending ReviewStart date:12/28/2010
Priority:NormalDue date:
Assignee:Morgan Haskel% Done:

0%

Category:-
Target version:3.x
Affected Puppet version: Branch:
Keywords:

Description

This ticket reflects a patch (and mailing list discussion) on the Puppet dev list with the subject line “Print output from postrun_command and prerun_command”.

The basic idea is: add options print_prerun_output and print_postrun_output which cause Puppet to print the output of the prerun and postrun commands, respectively.

For more information please see dev list discussion.

History

#1 Updated by James Turnbull over 2 years ago

  • Status changed from Unreviewed to Needs Decision

#2 Updated by James Turnbull over 2 years ago

  • Assignee set to Nigel Kersten

#3 Updated by Nigel Kersten over 2 years ago

Discussion: http://groups.google.com/group/puppet-dev/browse_thread/thread/4b8d5779a3a42216

#4 Updated by Nigel Kersten over 2 years ago

  • Status changed from Needs Decision to Investigating

My current stance is:

  • We should probably always print this output.
  • I don’t know what we should do about stderr, which seems equally important for these commands given we rely upon the exit code.

#5 Updated by Morgan Haskel over 2 years ago

I think it makes sense to always print the output from stdout and stderr

#6 Updated by Nigel Kersten over 2 years ago

We’d want to distinguish the two however.

Something like:

prerun command: show-actual-command
prerun_stdout: show-stdout
prerun_stderr: show-stderr-if-present
prerun_exit: show-exit-status-if-not-zero

I’m not sure whether this will work well for multi-line output, which stdout is often going to be.

anyone have any examples of their pre/post commands?

#7 Updated by Morgan Haskel over 2 years ago

For multi-line output would it be cleaner to append ‘prerun_stdout: ’ to each line of the output?

I definitely see multi-line output in my stdout.

#8 Updated by Jacob Helwig over 2 years ago

I do think pre-pending each line is the way to go. This would definitely make it easier to filter for (or filter out) these lines when looking through the logs.

#9 Updated by Nigel Kersten over 2 years ago

  • Status changed from Investigating to Accepted
  • Assignee deleted (Nigel Kersten)
  • Target version set to 2.7.x

Sold!

I’m convinced. Let’s do it.

#10 Updated by Ben Hughes over 1 year ago

  • Description updated (diff)
  • Status changed from Accepted to Unreviewed

#11 Updated by Dan Bode over 1 year ago

  • Description updated (diff)
  • Status changed from Unreviewed to Accepted

#12 Updated by Daniel Pittman over 1 year ago

  • Target version changed from 2.7.x to 3.x

I can’t tell if a CLA was signed by the original submitter or not. We can’t use that code without tracking that down.

A reimplementation without reference should be trivial, though, if someone wants to step up to the plate.

This isn’t a 2.7 feature by this point, though.

#13 Updated by James Turnbull over 1 year ago

It hasn’t been signed – the author is on the thread though:

[diff removed by editor]

#14 Updated by Daniel Pittman over 1 year ago

James Turnbull wrote:

It hasn’t been signed – the author is on the thread though:

[diff removed by editor]

…then we can’t use the code, and more copies of it make it more likely a reimplementation will be tainted by the original version.

#15 Updated by James Turnbull over 1 year ago

  • Status changed from Accepted to Requires CLA to be signed

How about we ask the author to sign one – hence my comment about him being on the thread. And there’s nothing wrong with adding the code in the diff here.

#16 Updated by James Turnbull over 1 year ago

  • Assignee set to Morgan Haskel

Hi Morgan – any chance you could please sign a CLA for your patch in http://groups.google.com/group/puppet-dev/browse_thread/thread/4b8d5779a3a42216? Just click on the link in the top right menu. Many thanks!

#17 Updated by Morgan Haskel over 1 year ago

I just signed the CLA.

#18 Updated by James Turnbull over 1 year ago

  • Status changed from Requires CLA to be signed to In Topic Branch Pending Review

Morgan – thanks so much for signing the CLA!

This is the proposed code. It’d be great to have this in a branch with a pull request too if possible but if you can’t do it we’ll handle it. Many thanks again!

diff --git a/configurer.rb b/configurer.rb 
index 31d31c2..194acc1 100644 
--- a/configurer.rb 
+++ b/configurer.rb 
@@ -41,11 +41,11 @@ class Puppet::Configurer 
   end 

   def execute_postrun_command 
-    execute_from_setting(:postrun_command) 
+    execute_from_setting(:postrun_command, Puppet[:print_postrun_output]) 
   end 

   def execute_prerun_command 
-    execute_from_setting(:prerun_command) 
+    execute_from_setting(:prerun_command, Puppet[:print_prerun_output]) 
   end 

   # Initialize and load storage 
@@ -200,11 +200,14 @@ class Puppet::Configurer 
     timeout 
   end 

-  def execute_from_setting(setting) 
+  def execute_from_setting(setting, print_output = false) 
     return if (command = Puppet[setting]) == "" 

     begin 
-      Puppet::Util.execute([command]) 
+      output = Puppet::Util.execute([command]) 
+      if print_output then 
+        Puppet.info(output) 
+      end 
     rescue => detail 
       raise CommandHookError, "Could not run command from #{setting}: 
#{detail}" 
     end 
diff --git a/defaults.rb b/defaults.rb 
index 4521a59..e0d2cda 100644 
--- a/defaults.rb 
+++ b/defaults.rb 
@@ -168,6 +168,12 @@ module Puppet 
     :postrun_command => ["", "A command to run after every agent run.  If 
this command returns a non-zero 
       return code, the entire Puppet run will be considered to have failed, 
even though it might have 
       performed work during the normal run."], 
+    :print_prerun_output => [false, 
+      "Boolean; whether to print output from the prerun_command at the 
'info' level." 
+    ], 
+    :print_postrun_output => [false, 
+      "Boolean; whether to print output from the postrun_command at the 
'info' level." 
+    ], 
     :freeze_main => [false, "Freezes the 'main' class, disallowing any code 
to be added to it.  This 
       essentially means that you can't have any code outside of a node, 
class, or definition other 
       than in the site manifest."] 

Also available in: Atom PDF