How to fail the chef run from a start handler?


#1

Hi,

I’m playing around with etckeeper and chef and wrote a start handler
that should prevent chef from doing anything, if /etc was modified
previously.

Is there any way to fail the chef run from a handler? They are executed
with run_report_safely, which catches all the exceptions.

Thanks for your help
Steffen

[1] https://github.com/opscode/chef/blob/master/lib/chef/handler.rb#L213


#2

On Saturday, November 16, 2013 at 3:26 PM, Steffen Gebert wrote:

Hi,

I’m playing around with etckeeper and chef and wrote a start handler
that should prevent chef from doing anything, if /etc was modified
previously.

Is there any way to fail the chef run from a handler? They are executed
with run_report_safely, which catches all the exceptions.

Thanks for your help
Steffen

[1] https://github.com/opscode/chef/blob/master/lib/chef/handler.rb#L213
You could override the #run_report_safely method. The code comment about "not overriding this method unless you know what you’re doing” applies to your case. Of course, the caveat there is that other handlers won’t run. For a more elegant approach, you’d need to patch that method, maybe using catch and throw, to allow for changing the state of the chef run to failure.

You could also move the code to the first recipe in the run_list if that’s something you can control.


Daniel DeLeo


#3

Hi Daniel,

thanks for your response!

That worked great, of course.

And here’s the result:
https://github.com/TYPO3-cookbooks/etckeeper/blob/master/templates/default/chef-client/etckeeper-handler.rb

Yours
Steffen

On Saturday, November 16, 2013 at 3:26 PM, Steffen Gebert wrote:

Hi,

I’m playing around with etckeeper and chef and wrote a start handler
that should prevent chef from doing anything, if /etc was modified
previously.

Is there any way to fail the chef run from a handler? They are executed
with run_report_safely, which catches all the exceptions.

Thanks for your help
Steffen

[1] https://github.com/opscode/chef/blob/master/lib/chef/handler.rb#L213
You could override the #run_report_safely method. The code comment about "not overriding this method unless you know what you’re doing” applies to your case. Of course, the caveat there is that other handlers won’t run. For a more elegant approach, you’d need to patch that method, maybe using catch and throw, to allow for changing the state of the chef run to failure.

You could also move the code to the first recipe in the run_list if that’s something you can control.


Daniel DeLeo