Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a list of the recipes applied to Chef node? [closed]

Tags:

chef-infra

I want to know if a given recipe has been applied to a list of N nodes managed to Chef. How can I do this easily.

like image 712
heinkunibert Avatar asked Nov 27 '12 08:11

heinkunibert


People also ask

Where are Chef recipes stored?

Cookbook location When the Chef recipes are executed, all cookbooks are stored on the node.

What is the difference between recipe and cookbook Chef?

Cookbooks are a collection of recipes. Apart from recipes, cookbooks contain other elements like metadata, attributes, libraries, resources, templates, and tests which helps the nodes to achieve their desired state. Cookbooks can be created by Chef commands or by the Chef command-line tool called Knife.

Which Chef component is hosts to which recipes and roles are applied during Chef client run?

Node: Hosts to which recipes and roles are applied during Chef client run. The primary features of a node are its attributes and run list.


3 Answers

I suspect you're looking for something like this:

knife search node "recipes:<recipe_name>"

This will apply for explicit run lists as well as expanded (implicit) run lists.

There is more detailed documentation on knife searches here:

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

like image 117
James Thompson Avatar answered Oct 18 '22 13:10

James Thompson


You can accomplish this easily using knife (knife is your friend!).

To get a list of all of your nodes:

knife node list

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

knife node list --environment <ENVIRONMENT>

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

knife node show <NODE_ID>

A knife node show, will display:

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

The Recipes: line is a list of the recipes which have been applied to a node.

Using knife search you can search for a set of nodes which meet specific criteria. Using it, you could find nodes that do or don't have a specific recipe applied to them.

like image 35
Jordan Dea-Mattson Avatar answered Oct 18 '22 14:10

Jordan Dea-Mattson


If you mean inside a recipe, You can use search, for example

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

In order to achieve your actual question, you could do something like:

['192.168.1.2'].include?(ruby_nodes.map{|node| node[:ipaddress]})
like image 37
daveharris Avatar answered Oct 18 '22 12:10

daveharris