Search code examples
rubychef-infrachef-recipecookbookrecipe

Force Chef to run recipes multiple times with different attributes


I have a cookbook (CB1) with a recipe (install_app) that will install applications. install_app actually executes a series of other recipes in CB1 and it uses attributes to change which application your installing and the application's settings.

I have recipes for each application that sets CB1 attributes and then they each call include_recipe CB1::install_app.

But it seems this does not work. Chef compiles all the recipes in the run list first and then executes them so only the first call to include_recipe CB1::install_app executes.

How do I force Chef to run the recipes multiple times?


Solution

  • This is not possible, recipes are considered to be singletons. What you want is to make a custom resource instead. Then you can invoke that resource multiple times with different inputs (properties).