Chef is a system and automation framework for cloud infrastructure which makes it easy to deploy applications and servers to any virtual, physical or cloud location. It is very powerful automation platform that transforms complex infrastructure into code. In previous article we have discussed about Installation of Chef Server and Chef Workstation.
In this article we will discussed about basic terminology of cookbook. Cookbooks are an essential part of Chef. You can easily create them using Knife, Chef’s command-line tool.
Basics of Cookbooks
A cookbook contain everything to support the installation and configuration of an application. Example: cookbook for Tomcat would provide all details to install and configure a fully configured Apache or Tomcat server.
Below is Cookbook Directory Structure.
drwxrwxr-x 10 devops devops 4096 Jul 20 03:44 ./
drwxrwxr-x 3 devops devops 4096 Jul 20 03:44 ../
drwxrwxr-x 2 devops devops 4096 Jul 20 03:44 attributes/
-rw-rw-r-- 1 devops devops 451 Jul 20 03:44 CHANGELOG.md
drwxrwxr-x 2 devops devops 4096 Jul 20 03:44 definitions/
drwxrwxr-x 3 devops devops 4096 Jul 20 03:44 files/
drwxrwxr-x 2 devops devops 4096 Jul 20 03:44 libraries/
-rw-rw-r-- 1 devops devops 276 Jul 20 03:44 metadata.rb
drwxrwxr-x 2 devops devops 4096 Jul 20 03:44 providers/
-rw-rw-r-- 1 devops devops 1448 Jul 20 03:44 README.md
drwxrwxr-x 2 devops devops 4096 Jul 20 03:44 recipes/
drwxrwxr-x 2 devops devops 4096 Jul 20 03:44 resources/
drwxrwxr-x 3 devops devops 4096 Jul 20 03:44 templates/
Let’s discuss some of the important terms of cookbook.
Recipes are used to configure the system.
– it is a collection of different type of resources.
– Is authored in Ruby.
– One recipe may have dependencies of other recipe.
– Recipes are collection of resources. Some of the resources are below.
User: Manage user like add, remove, update on node.
Group: To manage a local group.
Directory: To manage directory
File: To manage file directly on node.
Package: To manage a package.
For complete list of resources refer the link.
when cookbook is loaded during the chef-client run, these attributes are compared to the attributes that are already present on node. Chef-client will apply those new settings and values during the chef-client run on the node.
Template is used to dynamically generate static text files. We used it to to manage configuration file. To use template in recipe place the template file in cookbook’s template directory.
It is a file that will be in files directory and useful to copy file on node during chef-client run.
The contents of the metadata.rb file provides hints to the Chef server so that cookbooks are deployed to each node correctly. It includes package name, dependencies, description. It also allow chef server to build the run-list for the nodes correctly.
In next article we will create cookbook.
Thanks for reading. Do let us know if you have any feedback/suggestions.
Let us know if you want us to write us on any particular topic. We will try our best.