Configuring Chef Nodes Using Roles
The Scenario We continue to utilize Chef in our organization’s infrastructure, and it’s time to create a cookbook that installs Nginx. Creating new web servers, for either production or internal testing, is fairly common. We’d like to be able to control the run-list for all web server nodes in a single place though, and we’ve decided that we will use a new role to do this. After we’ve written our Nginx cookbook, we’ll deploy it to the first web server node using a role. Logging in On the lab overview page, we’ll see three EC2 instances: a Chef server ( we’ll call it chef), a workstation (we’ll call it worker) and a node (we’ll call it node). The shell prompts in this lab guide will reflect which one we’re running commands in at the moment. Get Nginx Running and Enabled on web-node1 We need to write a cookbook that installs the Nginx package and starts the service. This cookbook needs to be published and the recipe run on web-node1. Create the Cookbook After logging into worker, we can get into the provided Chef repository right away, with cd chef-repo. Once we’re in there, we can start building our cookbook: 1 cloud_user@worker]$ chef generate cookbook cookbooks/nginx Create the Recipe Edit the file ./cookbooks/nginx/recipes/default.rb with whichever text editor you like. When we’re done, the file should read like this (after our additions, and once we’ve removed the comments that were sitting in there already): ...