Chef node - check if recipe will run on it, looking inside roles as well
Asked Answered
P

1

5

I want to find out if a specific recipe will be run on a node from inside a different recipe. I can node.recipe?(recipe_name) method, however some of my recipies are managed by roles and recipe? does not seem to look into the roles run list.

Is there an easy way to find out if my recipie[redis] is going to be run on the current node?

Perihelion answered 26/6, 2013 at 21:13 Comment(0)
S
12

You're looking for the recipes method. Note the trailing s! So:

node.recipes.include?(recipe_name)

Also note that there is a similar pair of methods for role inspection. Those are role and roles. For both roles and recipes, the singular form is for those directly assigned and the plural for the fully resolved set.

Supper answered 26/6, 2013 at 21:19 Comment(3)
The best documentation on this I can find is the chef ticket CHEF-1587 which points at a chef source file node.rb, which seems to contradict your pluralization, no? Or am I missing a ruby-ism?Devanagari
It's not a contradiction, but rather an API with multiple access points for the same data. I presume you're referring to the recipe? method, which appears to also be a valid choice - preferable in fact. The difference is that recipes and roles are attributes that are auto-expanded: github.com/opscode/chef/blob/master/lib/chef/node.rb#L339, and chef allows you to query attributes via method calls.Supper
Oh, hmm, I did read that line before but didn't understand how it works. Makes more sense with your explanation. Thanks! (And yes, I was talking about the recipe? definition on line 246.)Devanagari

© 2022 - 2024 — McMap. All rights reserved.