Check if recipe is being used

Is there a way to tell if a recipe from a cookbook that I wrote is being used
by some other cookbook, or role? Trying to do some maintenance on our Chef
server and there are duplicate recipes and want to get them cleaned up. I have
multiple roles and environments so searching through it manually is a bit time
consuming.

which version of of chef you are using? chef stores all recipe name used by
a node in an attribute named 'recipes'. you can look into that

knife search node ':' -a recipes | grep 'name of recipe'

On Wed, May 28, 2014 at 8:04 AM, Adam adam.barrand@gmail.com wrote:

Is there a way to tell if a recipe from a cookbook that I wrote is being
used
by some other cookbook, or role? Trying to do some maintenance on our Chef
server and there are duplicate recipes and want to get them cleaned up. I
have
multiple roles and environments so searching through it manually is a bit
time
consuming.

You can also search directly:

knife search node ‘recipes:name-of-recipe’

This does require that all of your nodes are running a recent enough version of the chef-client that the recipe node attribute actually includes all of the derived recipes. I think that was fixed in version 11.10.0.

Eric

From: Ranjib Dey dey.ranjib@gmail.com
Reply: chef@lists.opscode.com chef@lists.opscode.com
Date: May 28, 2014 at 11:42:33 AM
To: chef@lists.opscode.com chef@lists.opscode.com
Subject: [chef] Re: Check if recipe is being used

which version of of chef you are using? chef stores all recipe name used by a node in an attribute named ‘recipes’. you can look into that

knife search node ‘:’ -a recipes | grep ‘name of recipe’

On Wed, May 28, 2014 at 8:04 AM, Adam adam.barrand@gmail.com wrote:
Is there a way to tell if a recipe from a cookbook that I wrote is being used
by some other cookbook, or role? Trying to do some maintenance on our Chef
server and there are duplicate recipes and want to get them cleaned up. I have
multiple roles and environments so searching through it manually is a bit time
consuming.

search key "recipes" is what your looking for. This way it checks the expanded run list that is established after chef explodes any roles (and environments I think?) that are assigned to the node.

to search for recipe 'install' from the 'widget' cookbook you would:
knife search node "recipes:widget::install"

note the escaping of the double colon

The only snafu with this approach is if someone hates you and uses include_recipe inside of another recipe. A recursive grep on your chef repo should reveal the culprit(s).

Sent from my iPhone

On May 28, 2014, at 11:04 AM, Adam adam.barrand@gmail.com wrote:

Is there a way to tell if a recipe from a cookbook that I wrote is being used
by some other cookbook, or role? Trying to do some maintenance on our Chef
server and there are duplicate recipes and want to get them cleaned up. I have
multiple roles and environments so searching through it manually is a bit time
consuming.