Print output from postrun_command and prerun_command

22 views
Skip to first unread message

Morgan Haskel

unread,
Dec 17, 2010, 1:36:25 PM12/17/10
to puppe...@googlegroups.com
Hi all,

I've recently started using postrun_command.  It seems very useful, but I'd really like to be able to optionally print the output from the postrun command so the users can see any relevant messages.  I patched 2.6.4 to get this working with the new options print_prerun_output and print_postrun_output (both defaulting to false).

My patch is included below.

~Morgan


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."]

Nigel Kersten

unread,
Dec 18, 2010, 10:23:13 AM12/18/10
to puppe...@googlegroups.com
On Fri, Dec 17, 2010 at 10:36 AM, Morgan Haskel <morgan...@gmail.com> wrote:
> Hi all,
>
> I've recently started using postrun_command.  It seems very useful, but I'd
> really like to be able to optionally print the output from the postrun
> command so the users can see any relevant messages.  I patched 2.6.4 to get
> this working with the new options print_prerun_output and
> print_postrun_output (both defaulting to false).
>
> My patch is included below.

Thanks for the patch Morgan.

Do you think it's reasonable to just always print the output of these
commands? I'm trying to think whether there are use cases where it
shouldn't be displayed that justify the added complexity of more
configuration settings.

> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Developers" group.
> To post to this group, send email to puppe...@googlegroups.com.
> To unsubscribe from this group, send email to
> puppet-dev+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/puppet-dev?hl=en.
>

Morgan Haskel

unread,
Dec 18, 2010, 3:40:18 PM12/18/10
to puppe...@googlegroups.com
It seems reasonable to me to always print the output.  I can't think of any cases where I wouldn't want that to happen.

Patrick

unread,
Dec 18, 2010, 3:53:32 PM12/18/10
to puppe...@googlegroups.com

On Dec 18, 2010, at 7:23 AM, Nigel Kersten wrote:

> On Fri, Dec 17, 2010 at 10:36 AM, Morgan Haskel <morgan...@gmail.com> wrote:
>> Hi all,
>>
>> I've recently started using postrun_command. It seems very useful, but I'd
>> really like to be able to optionally print the output from the postrun
>> command so the users can see any relevant messages. I patched 2.6.4 to get
>> this working with the new options print_prerun_output and
>> print_postrun_output (both defaulting to false).
>>
>> My patch is included below.
>
> Thanks for the patch Morgan.
>
> Do you think it's reasonable to just always print the output of these
> commands? I'm trying to think whether there are use cases where it
> shouldn't be displayed that justify the added complexity of more
> configuration settings.
>


If the configuration option is left, think that defaulting that setting to true on "--test" is reasonable?

Nigel Kersten

unread,
Dec 19, 2010, 9:35:06 AM12/19/10
to puppe...@googlegroups.com

I kind of consider us to have dug ourselves into a hole with "--test"
and I'd like to not make it any deeper :)

Patrick

unread,
Dec 19, 2010, 2:33:44 PM12/19/10
to puppe...@googlegroups.com

I think this sounds like the sort of thing --test was made for, but I can see your point, so whatever.

Nigel Kersten

unread,
Dec 19, 2010, 9:01:46 PM12/19/10
to puppe...@googlegroups.com

That's not a final decision in any way, and am happy to hear counter-arguments.

What should we do about stderr for these commands? Should we log
stdout *and* stderr ?

Paul Berry

unread,
Dec 28, 2010, 1:15:43 PM12/28/10
to puppe...@googlegroups.com
I've created a ticket in Redmine to track this work: http://projects.puppetlabs.com/issues/5703

On Fri, Dec 17, 2010 at 10:36 AM, Morgan Haskel <morgan...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages