Jennings, Jared L CTR USAF AFMC 46 SK/CCI
2011-Jun-06 14:37 UTC
[Puppet Users] logging output at err level, success as just a notice?
I''m trying to run pwck with Puppet 2.6.4. pwck checks the passwd file and makes sure that, for example, each user''s home directory exists. (And other stuff.) When everything is OK, it doesn''t say anything. So if it says something, I want to know it, and I want it to stand out from other exec output. So I have exec { "pwck": command => "/usr/sbin/pwck -r", logoutput => true, loglevel => err, } If pwck gives any output, it shows up at the err loglevel. But if everything is OK, I get: err: /Stage[main]/User::Valid/Exec[pwck]/returns: executed successfully (in purple, of course). I don''t want an err message when everything is fine. The documentation for the exec resource type (<http://docs.puppetlabs.com/references/latest/type.html>) says, about logoutput, "Values are true, false, on_failure, and any legal log level. Valid values are true, false, on_failure." (Take a second and read that again.) So I tried setting logoutput => err and no loglevel, and got: ''err: Could not run Puppet configuration client: Parameter logoutput failed: Invalid value "err". Valid values are true, false, on_failure.'' How can I make "executed successfully" a notice, and any output from pwck an err? If logoutput can indeed be set to any legal log level, does anyone know in what version of Puppet this works? -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Jacob Helwig
2011-Jun-06 15:53 UTC
Re: [Puppet Users] logging output at err level, success as just a notice?
On Mon, 06 Jun 2011 09:37:48 -0500, Jennings, Jared L CTR USAF AFMC 46 SK/CCI wrote:> > I''m trying to run pwck with Puppet 2.6.4. pwck checks the passwd file > and makes sure that, for example, each user''s home directory exists. > (And other stuff.) When everything is OK, it doesn''t say anything. So if > it says something, I want to know it, and I want it to stand out from > other exec output. > > So I have > > exec { "pwck": > command => "/usr/sbin/pwck -r", > logoutput => true, > loglevel => err, > } > > If pwck gives any output, it shows up at the err loglevel. But if > everything is OK, I get: > > err: /Stage[main]/User::Valid/Exec[pwck]/returns: executed successfully > > (in purple, of course). I don''t want an err message when everything is > fine. > > The documentation for the exec resource type > (<http://docs.puppetlabs.com/references/latest/type.html>) says, about > logoutput, "Values are true, false, on_failure, and any legal log level. > Valid values are true, false, on_failure." (Take a second and read that > again.) So I tried setting logoutput => err and no loglevel, and got: > ''err: Could not run Puppet configuration client: Parameter logoutput > failed: Invalid value "err". Valid values are true, false, on_failure.'' > > How can I make "executed successfully" a notice, and any output from > pwck an err? > > If logoutput can indeed be set to any legal log level, does anyone know > in what version of Puppet this works? >Unfortunately, the documentation is just plain wrong. loglevel is the only one that supports "any legal log level". logoutput really does only support true, false, and on_failure. Is pwck exiting non-zero when there is output? That should be sufficient to trigger the behavior it seems like you''re looking for if you have ''logoutput => on_failure'' in the exec. I tried running ''pwck -r'' on my Ubuntu machine, and it exited 2 with a bunch of warnings. I presume it would have exited 0 had there not been any warnings. -- Jacob Helwig
Jennings, Jared L CTR USAF AFMC 46 SK/CCI
2011-Jun-07 15:29 UTC
RE: [Puppet Users] logging output at err level, success as just a notice?
Helwig:> Unfortunately, the documentation is just plain wrong. loglevel is the > only one that supports "any legal log level". logoutput really does > only support true, false, and on_failure. > > Is pwck exiting non-zero when there is output? That should be > sufficient to trigger the behavior it seems like you''re looking for if > you have ''logoutput => on_failure'' in the exec.pwck indeed behaves nicely with its exitcodes - the problem is I want the output to be an err, not a notice: notice: /Stage[main]/User::Valid/Exec[pwck]/returns: user ''foo'': directory ''/home/foo'' does not exist notice: /Stage[main]/User::Valid/Exec[pwck]/returns: pwck: no changes err: /Stage[main]/User::Valid/Exec[pwck]/returns: change from notrun to 0 failed: /usr/sbin/pwck -r returned 2 instead of one of [0] at /etc/puppet/modules/user/manifests/valid.pp:11 If I set loglevel => err, that makes the output purple, but if pwck is happy, the loglevel setting also makes the "ran successfully" message an err. -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Jacob Helwig
2011-Jun-07 17:33 UTC
Re: [Puppet Users] logging output at err level, success as just a notice?
On Tue, 07 Jun 2011 10:29:12 -0500, Jennings, Jared L CTR USAF AFMC 46 SK/CCI wrote:> > Helwig: > > Unfortunately, the documentation is just plain wrong. loglevel is the > > only one that supports "any legal log level". logoutput really does > > only support true, false, and on_failure. > > > > Is pwck exiting non-zero when there is output? That should be > > sufficient to trigger the behavior it seems like you''re looking for if > > you have ''logoutput => on_failure'' in the exec. > > pwck indeed behaves nicely with its exitcodes - the problem is I want > the output to be an err, not a notice: > > notice: /Stage[main]/User::Valid/Exec[pwck]/returns: user ''foo'': > directory ''/home/foo'' does not exist > notice: /Stage[main]/User::Valid/Exec[pwck]/returns: pwck: no changes > err: /Stage[main]/User::Valid/Exec[pwck]/returns: change from notrun to > 0 failed: /usr/sbin/pwck -r returned 2 instead of one of [0] at > /etc/puppet/modules/user/manifests/valid.pp:11 > > If I set loglevel => err, that makes the output purple, but if pwck is > happy, the loglevel setting also makes the "ran successfully" message an > err. >Hm...yeah, sorry. I hadn''t noticed that the actual output was notice, and not err when the command fails. I was just testing around with echo, and setting "returns => 1" to get it to "fail", but I guess I just wasn''t looking closely enough. You can kind of hack Puppet to do this now, but only if the command you''re running is purely checking things, and does not have any side-effects. exec { ''pwck -r'': path => ''/usr/bin:/bin:/usr/sbin:/sbin'', logoutput => on_failure, loglevel => err, unless => ''pwck -r'', } By doing the "unless => ''pwck -r''", the resource won''t even show up as having been run if ''pwck -r'' returns 0. Having to run the command twice is a hack, but it''s the best I can think of at the moment. Seems reasonable that when "logoutput => on_failure" the actual output should be logged as an err, instead of a notice. Would you mind filing a feature request on the issue tracker[1]? [1] http://projects.puppetlabs.com -- Jacob Helwig
Jennings, Jared L CTR USAF AFMC 46 SK/CCI
2011-Jun-10 15:17 UTC
RE: [Puppet Users] logging output at err level, success as just a notice?
Helwig:> On Tue, 07 Jun 2011 10:29:12 -0500, Jennings, Jared L CTR USAF AFMC 46 > SK/CCI wrote: > > pwck indeed behaves nicely with its exitcodes - the problem is Iwant> > the output to be an err, not a notice > > exec { ''pwck -r'': > path => ''/usr/bin:/bin:/usr/sbin:/sbin'', > logoutput => on_failure, > loglevel => err, > unless => ''pwck -r'', > } > > By doing the "unless => ''pwck -r''", the resource won''t even show up as > having been run if ''pwck -r'' returns 0. Having to run the command > twice is a hack, but it''s the best I can think of at the moment.Ah, that''s a good hack. No problem for me, pwck runs quickly enough.> Seems reasonable that when "logoutput => on_failure" the actual output > should be logged as an err, instead of a notice. Would you mindfiling> a feature request on the issue tracker[1]?#7877. Thanks for your help! -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.