Cookbooks, Recipes, and Resources
- Create a new cookbook
- Write a simple recipe with two resources
- Run Chef with the cookbook on a node
/var/wwwis created and owned by www-data (Ubuntu) or apache (CentOS) user.
/var/www/index.htmlis rendered from a template.
- Answer the questions.
If your target system is Ubuntu, the owner is
If your target system is CentOS, the owner is
Create webserver Cookbook
Create a cookbok named
webserver in the cookbooks directory. It
should have a
default.rb recipe that configures two resources:
/var/wwwdirectory, which should be owned by the www-data or apache user.
/var/wwwrendered from a template, also owned by www-data or apache.
The source template should contain information about the node from its attributes. Minimum:
- Platform and Platform version (
- Default IP address (
- Fully qualified domain name (
- EC2 public IP address (
- The node's run list (
The file we're editing is HTML, but don't worry about HTML tags and
formatting, you may wrap the text in
metadata.rb file with the cookbook's initial version. Use
any version number you like using the form X.Y.Z, e.g., "1.0.0" or
Upload the cookbook to the Chef Server.
Note: We are not installing Apache HTTPD as part of this
index.html file can be viewed as plain text.
(Optional) Use a conditional for the user
The owner of the directory and template can be set using a conditional
based on the value of the
node['platform'] attribute so that it is
www-data when the node's platform is
apache when the
node's platform is
centos. As an optional exercise, you may do this
in the recipe.
Apply webserver Cookbook to a node
webserver cookbook's default recipe to your existing node
from the previous exercise using Knife. It should be the only node in
knife node list.
Log into the node and run
chef-client. Turn debug logging on to see
more information about the Chef run.
What is the run list of the node?
What resources were created on the node?
What is the content of the file