This part of the Chef tutorial includes the Chef Cheat Sheet. In this part, you will learn various aspects of Chef that are possibly asked in interviews. Also, you will have a chance to understand the most important Chef Terminologies.
AWS (Amazon Web Services) Solutions Architect Certification Training...
Cloud and DevOps Architect Master’s Course in Association with IBM...
Google Cloud Certification Training: The Professional Cloud Architect Training...
Microsoft Azure Master’s Program
Live Instructor-led Classes
Live Instructor-led Classes
Chef User Hand Book
Are you finding difficulty in remembering all the commands that you need in order to work with Chef? Guys don’t worry if you are a beginner and have no idea about how Chef works, this Chef cheat sheet will give you a quick reference of the basics that you must know to get started. While at Intellipaat, we support our learners with a handy reference, that’s the reason we have created this Cheat sheet. This cheat sheet is designed for the one who has already started learning about Chef but needs a handy reference sheet.
What is Chef?
It is open source and released by Opscode. It is a config management technology developed primarily to automate infrastructure provisioning.
It is used to deploy and manage servers on-premise or in the cloud.
It uses ruby as its reference language.
Now Discussing its features:
No assumptions are made, it gets the current status of the machine via certain mechanisms.
It is an excellent tool for integration with the cloud.
As it uses ruby, it is easy for anyone to get into chef with a basic development experience.
Learn DevOps in 16 hrs from experts
Before proceeding towards its components & basic commands, let’s understands the basic terminologies of Chef.
Node: A managed machine which executes the configuration for the node when the client runs.
Client: It is an authorized user in the chef API.
Cookbook: A collection of recipes, resources, attributes and definitions to configure a service or application.
Recipes: A list of resources to be added to a node, as it is written in ruby, so it gives you control of anything you would do in ruby.
Now let’s check the important component used in chef.
Knife: A System admin tool used to interact with server to take cookbooks and custom config and loading them into the server. Bootstrapping certain servers also possible.
Running knife- shows a list of commands that are supported.
Chef client: It runs on managed servers, gathers info about itself and syncs the cookbooks and compiles the collection of resources and converges it with the machine state.
Web UI: A web-based interface to allow to browse and edit cookbooks, nodes and clients.
Server/API: It is the heart of the system and exposes a REST API that is used by others. Manages the knife, web interfaces and nodes.
Chef basically works on a 3-tier client server model. Command line utilities are uploaded to the server and all nodes are registered with the server.
Chef has three main players in its architecture, which are Chef Workstation, Chef Server, Chef Nodes.
Configurations are developed and installed on local machine.
It is the center of the Chef setup.
Config files are uploaded here.
Some are hosted, and some are built on-premise.
End machines managed by the server.
Contains the client that sets communication between the server and node.
Ohai is another component of Chef Node which returns the current state of any node.
Runlist provides the recipes and the roles required for the node.Different from other config management tools that makes you define a relationship between each resource. Hence ordered list is easier to understand and use.
Using knife to get info about a node and the runlist:
A working unit of chef which is used for configuration and policy distribution.
Cookbooks will define a scenario and will contain everything which is required to provision that scenario.
Knife cookbookcreate name [NAME] creates a new directory for the cookbook
It is converted to JSON when installed in the server and returns the name, version and other properties. Most of the contents in it are for human use and is displayed on the interface.
Main parts are version and depends statements.
Version: Lets you set a specific version of cookbook.
Depends: Defines the other cookbooks, which are required for this to work, includes a version number which is optional.
It contains the documentation of the cookbook on how to use it and is useful when it is being shared with others. Markdown is supported while RDoc is the default.
Since it is open source, it allows the sharing of cookbooks in the community.
It supports downloading and sharing of cookbook on http://community.opscode.com/ to store, rate, and search shared cookbooks.
Test the cookbook to make sure it doesn’t break down during production.
example@localmach:~/chef-repo $ knife cookbook site install <cookbook name>
Run the test commands:
example@localmach:~/chef-repo $ knife cookbook test VTest
Running syntax check on ntp
Validating ruby files
Break something in it and test again:
example@localmach:~/chef-repo $ subl cookbooks/VTest/recipes/default.rb
node[‘ntp’][‘statsdir’] ].each do |ntpdir|
directory ntpdir do
Run test command again and check the output.
Limitation: Only runs a syntax check on ruby and .erb files.
Run ChefSpec and test kitchen to have a complete test done.
They are ruby objects with code behind them to config the system.
Each resource contains providers that tell the system how to run it.
Prints the logging message at the specified level
specify the level you want the message to be logged with level parameter.
Providers allow single package resource to be used on most UNIX- based OS.
Default action for a package is install. Eg: package “autoconf”
Specifying the version is possible
package “cucumber” do
Files, Directories and Templates
It provides file, remote file and cookbook file to manage files and resource to manage directories.
Create, remove and manage directory permissions.
Owner and group will be defaults for the client, usually root.
Defaults can make cookbooks more concise although they shouldn’t be confusing.
Allows you to manage and permissions and ownership of the files on the node.
To retrieve a file from the URL or cookbook, use remote_file or cookbook_file
They have a backup attribute that defines how many backfiles exist upon changing content.
Remote_file: It has the source parameter that contains the URL of the file to transfer.
Contains optional checksum that uses SHA-256.
Actions are limited to create and create_if_missing.
Cookbook_file: It is same as remote file, but files will be retrieved from files/directory structure.
Supports text-based config files using ERB.
Ruby code is wrapped in brackets. Things that are not parsed are not executed as ruby code.
Templates for complex configs can be created.
Just as in a cook_book file resource, source and node are set. Add variables attribute which assigns an array. The array will be made available in variable @ nameservers.
Search for node which are linux:knife search node “OS:linux”
To run on node as convergence:chef-client
Ro show environment:knife environment list -w
To delete environment:knife environment delete dev
To show knife environment:knife environment show dev
Download a Printable PDF of this Cheat Sheet
We have covered all the basics of Chef in this cheat sheet. If you want to start learning DevOps in depth then check out the DevOps Certification by Intellipaat.
Not only will you get to learn and implement Chef with a step by step guidance and support from us, but you will also get to learn other important topics in DevOps such as Docker, Git/GitHub, Ansible, Jenkins, Puppet, Selenium, Nagios and many more. You will also get 24*7 technical support to help you with any and all your queries, from the experts in the respective technologies here at intellipaat throughout the certification period. So, why wait? Check out the training program and enroll today!