O'Reilly logo

Learning Chef by Mischa Taylor, Seth Vargo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 14. Roles

Roles are a way of classifying the different types of services in your infrastructure, as shown in Figure 14-1.

Roles overview
Figure 14-1. Roles overview

Roles can be used to represent the types of servers in your infrastructure:

  • Load balancer
  • Application server
  • Database cache
  • Database
  • Monitoring

Although you can add recipes directly to a node’s run list, that’s not how your infrastructure works. Think about how you normally refer to servers:

  • “It’s a web server.”
  • “It’s a database server.”
  • “It’s a monitoring server.”

Roles allow you to conveniently encapsulate the run lists and attributes required for a server to be what you already think it is. Roles make it easy to configure many nodes identically without repeating yourself each time.

In addition to obvious roles, such as a “web server,” it is common practice to group any functionality that goes together into a role. The most common example is a base role, where you include all the recipes that should be run on every node.

Create a Web Server Role

Roles can be created and managed in the same fashion as data bags—there is a directory under chef-playground in which they are organized. The directory name is roles by default.

Use the chef-playground directory you created in Chapter 11. Use the same dual command prompt setup you used there. Start the chef-zero server on an open port in one window. We will be using port 9501 in the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required