[chef] Logging the output/result of an only_if command


Chronological Thread 
  • From: Ian Marlier < >
  • To: chef < >
  • Subject: [chef] Logging the output/result of an only_if command
  • Date: Thu, 25 Oct 2012 15:58:01 -0400

Hi, Chefs --

I have a few files on which I do syntax checks after Chef has generated the content, but before putting them into place.  For example, my sudoers files are dynamically generated, but rather than write directly to /etc/sudoers, I first write to a temp location.  Then, in the stanza that actually writes to /etc/sudoers, I include 'only_if "/usr/sbin/visudo -c /tmp/sudoers"'

This works fine, and has saved me from a few issues.  However, it doesn't really do anything useful in terms of telling me why the new file isn't being written to the correct place.  In an ideal world, I'd like to be able to log either the output of the only_if command, or just the fact that it returned a non-zero error code and what that return code was.  However, I'm sort of at a loss when it comes to combining a system command and a Chef::Log stanza, conditional on the output of that system command.

Does anyone have any thoughts on how to do this?

Thanks!

- Ian

--
Ian Marlier | Manager of Platform Operations
Brightcove, Inc.
290 Congress Street, 4th Floor, Boston, MA 02110
" target="_blank">




Archive powered by MHonArc 2.6.16.

§