0

I want to do the equivalent via the CLI that clicking on the stack, selecting only instances in a specific layer and running Execute Recipes command (or alternatively trigger the Configure lifecycle step).

I need to do this programmatically, there is an option to do it at the Stack level but that does not help,

Trying to avoid something like the following, I will probably end up pulling the layer members into an array and then hitting them independently as suggested below. Not great though since I'll have to add static information for Stack & Layer info.

 if deploy[:application_type] != 'php'
Chef::Log.debug("Skipping mod_php5_apache2::php application #{application} as it is not an PHP app")
next

end

TheFiddlerWins
  • 2,973
  • 1
  • 14
  • 22

1 Answers1

1

You'll have to do this in two steps, firstly get the instances in a specific layer using describe-instances by setting the --layer-id argument, then run your command on those instances using create-deployment by setting the --instance-ids argument.

Another option is to make your custom recipes do nothing if they're not executed on the right layer or the app type is wrong. This technique is used quite frequently in the default cookbooks, here's an example of skipping a deploy if it's not a PHP app. You could then run your recipe on all instances but it would only do something on specific layers.

thexacre
  • 1,849
  • 12
  • 14
  • Will check this as answered if no one can give me a better one, I figured this was how I'd have to do it but what a pain. I guess I'll script it in Jenkins – TheFiddlerWins Jan 15 '15 at 14:39
  • @TheFiddlerWins I avoided expressing an opinion in my answer but putting conditions in my recipes to skip them is actually my preferred method as it's arguably simpler and avoids the risk of running a recipe on the wrong instance. What you can do is create another recipe that is nothing but include_recipe statements wrapped in some condition to make a list of recipes which only run on certain instances - kind of like additional lifecycle event types. – thexacre Jan 15 '15 at 22:16