(Day 09) Task : Chef Methodology , Cookbook Generation :-


Chef is a powerful configuration management tool in the DevOps ecosystem that automates the deployment and management of infrastructure. It uses a declarative language to define system configurations, ensuring consistency and scalability across environments.
Chef Workstation is the place where all the coding, testing, and configuration happens before anything is pushed to the Chef server or nodes.
What is Chef Workstation?
It is the local system (our laptop or desktop) where we:
Write and test Chef code (recipes/cookbooks).
Interact with the Chef server using CLI tools like
knife
.Use tools like Test Kitchen, InSpec, and ChefSpec for testing.
Upload and manage cookbooks on the Chef server.
Working of Chef Workstation :-
Authoring Configuration:
- You write recipes and cookbooks using Ruby DSL.
Testing Code:
Use Test Kitchen to run cookbooks in local virtual machines.
Validate code using tools like Foodcritic and Cookstyle.
Interaction with Chef Server:
- Use
knife
to upload cookbooks, manage nodes, roles, environments, etc.
- Use
Push to Chef Server:
- Once tested, code is pushed to the Chef server which distributes it to the nodes.
Nodes Execute:
- Nodes pull configurations from the Chef server and apply them during the chef-client run.
What is a Chef Cookbook?
A Cookbook is the basic unit of configuration and policy distribution in Chef.
Why Use a Cookbook?
To automate tasks like installing software, creating users, or configuring services.
To keep your infrastructure consistent across multiple servers.
To reuse configuration code by organizing it neatly.
What's Inside a Cookbook?
A Cookbook is a directory with a specific structure. Each folder/file has a purpose:
✅ Common Components:
recipes/
Contains
.rb
files written in Ruby.Each recipe defines a series of configuration steps.
attributes/
Stores default values (e.g., software versions).
Used inside recipes for dynamic configuration.
templates/
Contains
.erb
files (Embedded Ruby).Used for generating dynamic config files.
files/
Contains static files (like images, scripts, etc.).
These are copied directly to nodes.
metadata.rb
- Describes cookbook name, version, dependencies.
-
- Provides human-readable documentation about the cookbook.
libraries/
(optional)- Custom Ruby code to extend Chef resources.
resources/
andproviders/
(optional)- For writing custom Chef resources (advanced usage).
Creating Cookbook in Linux Machine :-
Create a Linux Machine(Vm) using any platform (like - AWS , GCP).
Go to Google & Search www.chef.io
- Go to Downloads (
Ctrl + J
) & Copy address url.
- Go to Downloads (
Open and access machine using putty
First login as ec2-user.
ec2-user sudo su yum update -y
Now in Vm paste url in wget section which helps in staging the chef file & use ls which shows chef package then use that package using yum install <chef workstation(package)> -y
Now create a directory / cookbooks(name of directory) inside which all cookbooks will be present and will be generated.
mkdir cookbooks # This is used to create a directory naming cookbooks. ls # This helps in showing all content present. cd cookbooks # Change directory. chef generate cookbook test-cookbook # To Generate Cookbook naming test-cookbook inside directory cookbooks
What is a Chef Recipe :-
A Recipe is a collection of resources that describes how a part of the system should be configured.
A Recipe is a script written in Ruby that tells Chef what to do on a system.
Written in Ruby DSL.
Example: Installing Nginx, starting a service, creating a file.
Features of Recipes :
Declarative: Define what the system should look like.
Reusable: Can be used across multiple nodes.
Conclusion :-
- Creation of a recipe will be described in Tomorrow’s Task .
Subscribe to my newsletter
Read articles from Aditya Sharma directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Aditya Sharma
Aditya Sharma
DevOps Enthusiast | Python | Chef | Docker | GitHub | Linux | Shell Scripting | CI/CD & Cloud Learner | AWS