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.
Cookbook location When the Chef recipes are executed, all cookbooks are stored on the node.
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.
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.
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
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.
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]})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With