How to get a list of recipes applied to a node chef?

I want to know if this recipe was applied to a list of N nodes managed by a chef. How can I make it easy.

+8
chef
source share
3 answers

You can easily do this using a knife (the knife is your friend!).

To get a list of all your nodes:

knife node list 

To get a list of all your nodes in a given environment:

 knife node list --environment <ENVIRONMENT> 

With a list of nodes in hand, you can display the details for a node using:

 knife node show <NODE_ID> 

The show node appears, it will display:

 Node Name: Environment: FQDN: IP: Run List: Roles: Recipes: Platform: Tags: 

The Recipes: string is a list of recipes that have been applied to the node.

Using a knife search, you can search for a set of knots that meet certain criteria. Using it, you can find nodes that use or do not have a specific recipe applied to them.

+4
source share

I suspect you are looking for something like this:

 knife search node "recipes:<recipe_name>" 

This applies to explicit launch lists, as well as to extended (implicit) launch lists.

This contains more detailed documentation on finding knives:

http://docs.opscode.com/knife_search.html

+4
source share

If you mean inside the recipe, you can use search , for example

 ruby_nodes = search(:node, "recipes:ruby_build") 

To reach your current question, you can do something like:

 ['192.168.1.2'].include?(ruby_nodes.map{|node| node[:ipaddress]}) 
0
source share

All Articles