0

Can anyone suggest in chef a best way to handle looping and running a certain recipe. For example I have this in my recipe

apps_databag = search("aws_opsworks_app")

apps_databag.each do |app_settings|

case app_settings['app_source']['type']
  when 's3'
   include_recipe 'recipe'
  when 'git'
   include_recipe 'recipe2'
  else
   Chef::Log.warn("*** WARNING!! Cannot find app deployment type. Please check App .. Aborting ***")
end

Background.. in 1 stack we have many APP that are deployed in different Server layers. We did because it cannot share RDS in two different stack. It's definitely working , now when we loop the APP we have do a trick that it will run this recipe according to it's type unfortunately include_recipe is not a good choice and for the sake of the recipe we don't want to make this recipe bloody to maintain by injecting more lines

Any suggestion for this scenario?

Drixson Oseña
  • 3,631
  • 3
  • 23
  • 36

2 Answers2

2

If you have multiples apps of each type to deploy on the same machine, move your recipe into a custom resource/LWRP.

A recipe can be included just once, so your loops won't do for multiples apps of same type.

Then you'll replace our include_recipe calls by resource definitions in your case statement.

Without more details on what is in your recipe, I can't give more advice on it.

Tensibai
  • 15,557
  • 1
  • 37
  • 57
0

Not clear what you are asking for. include_recipe is a helper to run one recipe from another. It isn't a resource per se, but you can use code basically like what you have there (give or take that it should probably be app_settings["type"]).

coderanger
  • 52,400
  • 4
  • 52
  • 75