Using search to find nodes

If you are running your infrastructure in any type of virtualized environment, such as a public or private cloud, the server instances that you use will change frequently. Instead of having a well-known set of servers, you destroy and create virtual servers regularly.

In this situation, your cookbooks cannot rely on hardcoded server names when you need a list of available servers.

Chef provides a way to find nodes by their attributes, for example, their roles. In this section, we'll see how you can retrieve a set of nodes to use them in your recipes.

Getting ready

Make sure that you have a cookbook called my_cookbook, as described in the Creating and using cookbooks section in Chapter 1, Chef Infrastructure.

How to do it... ...

Get Chef Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.