# Graceful exit mid chef run

**URL:** <https://discourse.chef.io/t/graceful-exit-mid-chef-run/3341>\
**Category:** Chef Infra (archive)\
**Created:** [November 27, 2012, 12:52am UTC](https://discourse.chef.io/t/graceful-exit-mid-chef-run/3341 "2012-11-27T00:52:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wade\_Peacock](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/wade_peacock/32/78_2.png) [@Wade\_Peacock](https://discourse.chef.io/u/Wade_Peacock)\
**Post date:** [November 27, 2012, 12:52am UTC](https://discourse.chef.io/t/graceful-exit-mid-chef-run/3341/1 "2012-11-27T00:52:27Z")

</div>

Hi All,

I there a graceful way to exit a chef run (skill all remain cookbooks/recipes) if a condition is not met.

Scenario:

Recipe 1  
Recipe 2 (condition not met)  
Recipe 3 Skip  
Recipe 4 Skip

Use would be where a manual sysadmin step is need prior to continuing.

I’m looking for a way to prevent a tangled web of only\_if/not\_if statements.

I’ve tried using native ruby alert(“message here”) but it exits abruptly, and chef run is not reported back to server.

Wade Peacock  
Production IT | Vision Critical  
direct 604.629.9358  
mobile 604.363.8137

[www.visioncritical.com](http://www.visioncritical.com)[http://www.visioncritical.com/](http://www.visioncritical.com/)

New York | London | Vancouver | Paris | Sydney | Chicago | San Francisco | Toronto | Montreal | Calgary

---

<div class="post-metadata">

**Author:** ![AJ\_Christensen](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/aj_christensen/32/525_2.png) [@AJ\_Christensen](https://discourse.chef.io/u/AJ_Christensen)\
**Post date:** [November 27, 2012, 12:55am UTC](https://discourse.chef.io/t/graceful-exit-mid-chef-run/3341/2 "2012-11-27T00:55:14Z")

</div>

Hello,

Sorry for top-post; our runlist\_modifiers cookbook allows for one to raise  
a RestrictedRecipe error, which unfurls the run-list so to speak, so that  
dependant (or depended-upon) recipes are also skipped. [0](http://community.opscode.com/cookbooks/runlist_modifiers)

Cheers,

--AJ

On 27 November 2012 13:52, Wade Peacock [Wade.Peacock@visioncritical.com](mailto:Wade.Peacock@visioncritical.com)wrote:

> Hi All,\*\*\*\*
> 
> * * *
> 
> I there a graceful way to exit a chef run (skill all remain  
> cookbooks/recipes) if a condition is not met.\*\*\*\*
> 
> * * *
> 
> Scenario:\*\*\*\*
> 
> * * *
> 
> Recipe 1 \*\*\*\*
> 
> Recipe 2 (condition not met)\*\*\*\*
> 
> Recipe 3 Skip\*\*\*\*
> 
> Recipe 4 Skip\*\*\*\*
> 
> * * *
> 
> Use would be where a manual sysadmin step is need prior to continuing. \*\*\*  
> \*
> 
> * * *
> 
> I'm looking for a way to prevent a tangled web of only\_if/not\_if  
> statements.\*\*\*\*
> 
> * * *
> 
> I've tried using native ruby alert("message here") but it exits abruptly,  
> and chef run is not reported back to server.\*\*\*\*
> 
> * * *
> 
> * * *
> 
> _Wade Peacock_  
> _Production IT | Vision Critical_  
> _direct \* 604.629.9358_\*\*\*
> 
> _mobile \* 604.363.8137_\*\*\*
> 
> * * *
> 
> [www.visioncritical.com](http://www.visioncritical.com)\*\*\*\*
> 
> New York | London | _Vancouver_ | Paris | Sydney | Chicago | San  
> Francisco | Toronto | Montreal | Calgary\*\*\*\*
> 
> * * *

---

<div class="post-metadata">

**Author:** ![Jesse\_Nelson](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/jesse_nelson/32/262_2.png) [@Jesse\_Nelson](https://discourse.chef.io/u/Jesse_Nelson)\
**Post date:** [November 27, 2012, 1:17am UTC](https://discourse.chef.io/t/graceful-exit-mid-chef-run/3341/3 "2012-11-27T01:17:55Z")

</div>

You can also simply "return" from your recipe when some condition not met:

```
return if node[:platform_family] == "debian"

```

The HeavyWater cookbook is much more robust, but this does the job.

On Tue, Nov 27, 2012 at 9:55 AM, AJ Christensen [aj@junglist.gen.nz](mailto:aj@junglist.gen.nz) wrote:

> Hello,
> 
> Sorry for top-post; our runlist\_modifiers cookbook allows for one to raise  
> a RestrictedRecipe error, which unfurls the run-list so to speak, so that  
> dependant (or depended-upon) recipes are also skipped. [0](http://community.opscode.com/cookbooks/runlist_modifiers)
> 
> Cheers,
> 
> --AJ
> 
> On 27 November 2012 13:52, Wade Peacock [Wade.Peacock@visioncritical.com](mailto:Wade.Peacock@visioncritical.com)wrote:
> 
> > Hi All,\*\*\*\*
> > 
> > * * *
> > 
> > I there a graceful way to exit a chef run (skill all remain  
> > cookbooks/recipes) if a condition is not met.\*\*\*\*
> > 
> > * * *
> > 
> > Scenario:\*\*\*\*
> > 
> > * * *
> > 
> > Recipe 1 \*\*\*\*
> > 
> > Recipe 2 (condition not met)\*\*\*\*
> > 
> > Recipe 3 Skip\*\*\*\*
> > 
> > Recipe 4 Skip\*\*\*\*
> > 
> > * * *
> > 
> > Use would be where a manual sysadmin step is need prior to continuing. \*\*  
> > \*\*
> > 
> > * * *
> > 
> > I'm looking for a way to prevent a tangled web of only\_if/not\_if  
> > statements.\*\*\*\*
> > 
> > * * *
> > 
> > I've tried using native ruby alert("message here") but it exits abruptly,  
> > and chef run is not reported back to server.\*\*\*\*
> > 
> > * * *
> > 
> > * * *
> > 
> > _Wade Peacock_  
> > _Production IT | Vision Critical_  
> > _direct \* 604.629.9358_\*\*\*
> > 
> > _mobile \* 604.363.8137_\*\*\*
> > 
> > * * *
> > 
> > [www.visioncritical.com](http://www.visioncritical.com)\*\*\*\*
> > 
> > New York | London | _Vancouver_ | Paris | Sydney | Chicago |  
> > San Francisco | Toronto | Montreal | Calgary\*\*\*\*
> > 
> > * * *
