# Design about Running recipes Incrementally and Cleanup after Recipe removal

**URL:** <https://discourse.chef.io/t/design-about-running-recipes-incrementally-and-cleanup-after-recipe-removal/2572>\
**Category:** Chef Infra (archive)\
**Created:** [March 19, 2012, 4:04pm UTC](https://discourse.chef.io/t/design-about-running-recipes-incrementally-and-cleanup-after-recipe-removal/2572 "2012-03-19T16:04:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hui\_Hu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/hui_hu/32/254_2.png) [@Hui\_Hu](https://discourse.chef.io/u/Hui_Hu)\
**Post date:** [March 19, 2012, 4:04pm UTC](https://discourse.chef.io/t/design-about-running-recipes-incrementally-and-cleanup-after-recipe-removal/2572/1 "2012-03-19T16:04:57Z")

</div>

Hello everyone and Chef designers,

I’m a new Chef user, now want to find some solution for 2 problems:  
Incremental Recipe Running and Cleanup after Recipe removal

1. Running recipes Incrementally  
Assume a node has a run\_list : [A,B,C] , now I want to add a new recipe D  
into its run\_list, then run chef-client. So chef-client will re-run  
A,B,C,D. However, re-run A,B,C is unneccessary, and sometimes I don’t want  
A,B,C to be re-ran which will cause service provided in A,B,C to be restart.

Is it possible to let chef-client check the diff of the two run\_lists and  
only run the added recipe and re-run the recipe which has been modified or  
whoes attribute is modified.

1. Cleanup after Recipe removal  
This problem is described here :  
[http://help.opscode.com/discussions/questions/271-cleanup-after-recipe-removal](http://help.opscode.com/discussions/questions/271-cleanup-after-recipe-removal).

It says when a recipe is removed from the old run\_list, can chef-client  
detects the change, and remove the packages/files/init.d services installed  
by that recipe ? Maybe adding a rollback() method in every recipe to do  
this kind of removal and let chef-client call rollback() automactically ?

Looking forward to the feedback 🙂

Thanks & Best Regards,  
Hui Hu

---

<div class="post-metadata">

**Author:** ![Brad\_Knowles](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/brad_knowles/32/716_2.png) [@Brad\_Knowles](https://discourse.chef.io/u/Brad_Knowles)\
**Post date:** [March 19, 2012, 4:23pm UTC](https://discourse.chef.io/t/design-about-running-recipes-incrementally-and-cleanup-after-recipe-removal/2572/2 "2012-03-19T16:23:22Z")

</div>

On Mar 19, 2012, at 4:04 PM, Hui Hu wrote:

> 1. Running recipes Incrementally  
> Assume a node has a run\_list : [A,B,C] , now I want to add a new recipe D into its run\_list, then run chef-client. So chef-client will re-run A,B,C,D. However, re-run A,B,C is unneccessary, and sometimes I don't want A,B,C to be re-ran which will cause service provided in A,B,C to be restart.

If you write your recipes correctly, when A,B, & C run for the second time, they will be able to determine that nothing needs to change, and therefore they won't restart any services. This is what it means to be "idempotent". The Opscode folks are responsible for making their code idempotent inside of chef-client, and it's up to _YOU_ to make sure that your recipes are also idempotent.

Otherwise, you made the bed of thorns, and now you get to lay in it.

> 1. Cleanup after Recipe removal  
> This problem is described here : [Chef Support for Automation & DevOps | Chef](http://help.opscode.com/discussions/questions/271-cleanup-after-recipe-removal) .
> 
> It says when a recipe is removed from the old run\_list, can chef-client detects the change, and remove the packages/files/init.d services installed by that recipe ? Maybe adding a rollback() method in every recipe to do this kind of removal and let chef-client call rollback() automactically ?

Again, that's up to you. You write your cookbooks and recipes in such a way that they can appropriately de-install themselves, and that will happen.

Otherwise, well, you get out of the system what you put into it.

--  
Brad Knowles [bknowles@ihiji.com](mailto:bknowles@ihiji.com)  
SAGE Level IV, Chef Level 0.0.1

---

<div class="post-metadata">

**Author:** ![Hui\_Hu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/hui_hu/32/254_2.png) [@Hui\_Hu](https://discourse.chef.io/u/Hui_Hu)\
**Post date:** [March 21, 2012, 10:05am UTC](https://discourse.chef.io/t/design-about-running-recipes-incrementally-and-cleanup-after-recipe-removal/2572/3 "2012-03-21T10:05:11Z")

</div>

Hi Brad and All,

Thanks for your comments.

About 1) Running recipes Incrementally. Opscode support staff says  
"Incremental application of recipes is in the planning stage right now" (

> **[Chef Support for Automation & DevOps | Chef](https://www.chef.io/support)**
>
> Need help? Get in touch with the Chef Support team via email, social media, or support ticket. Learn more about how to find the right Chef support for your needs.

)

About 2) Cleanup after Recipe removal . As you said, we can write code to  
do the cleanup manually , but it would be somewhat complicated. It would  
be perfect if Chef Client can do it automatically .

Thanks & Best Regards,  
Phone: 158 1011 7406  
Hui Hu 胡 辉

2012/3/20 Brad Knowles [bknowles@ihiji.com](mailto:bknowles@ihiji.com)

> On Mar 19, 2012, at 4:04 PM, Hui Hu wrote:
> 
> > 1. Running recipes Incrementally  
> > Assume a node has a run\_list : [A,B,C] , now I want to add a new recipe  
> > D into its run\_list, then run chef-client. So chef-client will re-run  
> > A,B,C,D. However, re-run A,B,C is unneccessary, and sometimes I don't want  
> > A,B,C to be re-ran which will cause service provided in A,B,C to be restart.
> 
> If you write your recipes correctly, when A,B, & C run for the second  
> time, they will be able to determine that nothing needs to change, and  
> therefore they won't restart any services. This is what it means to be  
> "idempotent". The Opscode folks are responsible for making their code  
> idempotent inside of chef-client, and it's up to _YOU_ to make sure that  
> your recipes are also idempotent.
> 
> Otherwise, you made the bed of thorns, and now you get to lay in it.
> 
> > 1. Cleanup after Recipe removal  
> > This problem is described here :  
> > [Chef Support for Automation & DevOps | Chef](http://help.opscode.com/discussions/questions/271-cleanup-after-recipe-removal).
> > 
> > It says when a recipe is removed from the old run\_list, can chef-client  
> > detects the change, and remove the packages/files/init.d services installed  
> > by that recipe ? Maybe adding a rollback() method in every recipe to do  
> > this kind of removal and let chef-client call rollback() automactically ?
> 
> Again, that's up to you. You write your cookbooks and recipes in such a  
> way that they can appropriately de-install themselves, and that will happen.
> 
> Otherwise, well, you get out of the system what you put into it.
> 
> --  
> Brad Knowles [bknowles@ihiji.com](mailto:bknowles@ihiji.com)  
> SAGE Level IV, Chef Level 0.0.1
