How To Install Chef in 6 Simple Steps

If you’re looking for a tool to automate your infrastructure provisioning, Chef has what you need. A Chef is a configuration management tool that simplifies the manual and repetitive tasks for infrastructure management. In this article, we’ll cover simple Chef installation and its configuration on CentOS.

Boost Your Salary 5x in 2024

Docker Certified Associate Training CourseExplore Program
Boost Your Salary 5x in 2024

Before going through the installation process, we’ll briefly cover Chef’s architecture, which includes three components: 

  • The workstation - Where the system admin sits.
  • The server - Where all the configuration files are stored.
  • The client or the node systems - The systems that require the configuration.

In our demo, we’ll use just one client as an example to simplify the process. Typically, a user may have multiple clients.

1. Chef Installation: ChefDK

The following example is using Oracle VM VirtualBox Manager, and two machines—the master and the node. Both of these are sent to seven machines on the server.

oracle

This demo is using this as a service on the cloud. Let's look at the master system first, which includes an open terminal that displays a black background with green text. 

anjali-localhost

This is the node system, which has a black background with white text. 

anjali-client.

This is how users can easily differentiate the two.

Let’s begin with the master system. The first step for installing Chef is to download ChefDK and use the following command:

wget

After the command execution:

  • Go to your browser and type chefdk
  • Open the first link
  • You will find different versions of chefdk depending on the operating system you are using. Select the option that is compatible with your operating system

chef-dev-kit.

red-hat

The latest version today is Red Hat Enterprise Linux 8. 

Boost Your Salary 5x in 2024

Docker Certified Associate Training CourseExplore Program
Boost Your Salary 5x in 2024

For this Chef installation demo, we are using Red Hat Enterprise Linux 7. If you prefer to use the latest version, you can check the same source and copy the required URL.

  • Copy the URL and return to your terminal

red-hat2

  • Paste the URL there, and Chef will start downloading

downloading

  • After downloading ChefDK, , the next step is to install it

install

Our downloaded version of ChefDK in this demo is then copied and pasted down in the command.

The ChefDK installation is now complete, but we will also add a sample recipe on our work station by doing the following: 

  • Create a folder called “chef-repo”

mkdir chef-repo

  • Next, we’ll move into this folder

cd chef-repo

  • Create a folder that will hold all our cookbooks
  • After making that folder, move inside that folder, too

mkdir cookbooks

cd cookbooks

cd-cookbooks

Boost Your Salary 5x in 2024

Docker Certified Associate Training CourseExplore Program
Boost Your Salary 5x in 2024

In the next step, we will create a cookbook that will have the actual recipe with the following command:

chef generate cookbook sample

“Sample” here is the name of the cookbook. 

The cookbook is now created, and for the next step, you’ll want to move into the cookbook.

cookbook-ready

When we create the cookbook, a hierarchical structure is automatically generated. Let's look at this hierarchical structure to understand what exactly a cookbook is.

To see the hierarchical structure, use the following command: 

tree 

tree

You can see here within our cookbook we have a folder, “recipes,” and under this, there is the default.rb recipe

This is where we'll be creating our recipe, so we'll alter the content of default.rb.

gedit-default

Let’s move on to writing our recipes. 

  • Open the recipes folder 

cd ./recipes 

  • Open the default.rb recipe in gedit

gedit default.rb

The recipe used in this Chef Installation demo involves installing the httpd package on our client node. This is your Apache server, which will also host a very straightforward webpage.

Additionally, the recipes in Chef are written in Ruby.

Boost Your Salary 5x in 2024

Docker Certified Associate Training CourseExplore Program
Boost Your Salary 5x in 2024

cookbook-sample

The first line is where httpd is installed. 

The second line for service is where you start or enable the httpd service on that line.

That's our first task. The second part of the Chef Installation process includes creating a web page. 

This is when you store your web page, which is a default path where our web pages are created. 

The text that will appear on our web page will be, "Congratulations on completing the Chef demo."

After this recipe is created, save and close it. The next step in this Chef Installation process will move on to the server.

2. Move on to the Chef Server 

Now that the recipe has been created, all of the work at the Chef Workstation is complete. 

It is now time to move on to the server.

chef-manage

In our demo, we will be using the server as a service on the cloud, so go to your browser and type manage.chef.io.

This is the Chef server log-in the homepage. 

  • Click on “Click here to get started!”

To move further in the Chef installation process, a free Chef server account is required, so you’ll need to create one if you don’t have one already.. The process to create an account is fast and simple, and is shown below:

free-trial

Boost Your Salary 5x in 2024

Docker Certified Associate Training CourseExplore Program
Boost Your Salary 5x in 2024

You'll then receive an email from Chef software. Click on this link to verify your email address. You’ll then be prompted to create a password. 

Let's continue on our Chef Workstation machine.

  • Log in with your username and password.

The first time you log into your Chef server, you'll see a pop-up appear, where you will need to create a new organization.

This organization is the name that will be associated with a collection of client machines.

The first thing you’ll do is go to the administration tab and download the starter kit.

During this part of the Chef installation process, ensure you're on your workstation because this is where your folder needs to be installed. It downloads when the file is saved. 

The chef-starter kit is the key to connecting Chef Workstation with the server and the server with the node.

3. Move the Zip Folder Into the Cookbooks Folder and Unzip It There

In our case, the two machines are "the workstation and the node" and "the one server."

  • Let's return to our root directory. The Chef starter zip file is in the downloads folder 
  • First, move the zip folder into the “my cookbooks” folder 
  • Next, unzip the folder

Boost Your Salary 5x in 2024

Docker Certified Associate Training CourseExplore Program
Boost Your Salary 5x in 2024

The cookbooks folder is the one that contains the recipe, and that is where the knife tool command is present so that these recipes can be sent over to the server.

Next, we’ll check the contents of our cookbook to ensure that our chef-starter.zip file is in it.

chef-start

You can see it's here. Our next step is to unzip this folder.

unzip-folder

Once it’s unzipped, your Chef Workstation and your server are now linked. 

After linking the workstation to your server, the next step in the Chef installation process is to upload the recipes onto the server.

Get the overview of Chef and demonstrate the Chef configuration with the DevOps Certification Training Course. Enroll today!

Boost Your Salary 5x in 2024

Docker Certified Associate Training CourseExplore Program
Boost Your Salary 5x in 2024

4. Use the Knife Command to Upload the Recipes to the Server

There is a tool called a knife that enables the communication and transfer of cookbooks between the three machines. 

The knife command tool is used to transfer or upload recipes, which we created on the server’s workstation. Prior to executing the command, we’ll need to move into the cookbooks directory. This is where we unzipped the Chef starter kit, so that is where the knife command can be found.

  • Execute the knife command 

knife cookbook upload sample

After you execute the command, you can see the entire cookbook being uploaded onto the server.

/root-locahost

5. Make It Possible for the Node and the Chef Server to Communicate.

Check the server after the knife command is executed.

  • Move to your browser, where you opened your Chef server
  • Go to policy. Here, you can find the uploaded cookbook, sample

It's the first time it has been uploaded, so it is version 0.1.0.

all-cookbook

When you go to the Nodes tab, you will see that there are no nodes present.

If there aren’t any nodes, there isn’t an available machine to execute your cookbooks on.

Boost Your Salary 5x in 2024

Docker Certified Associate Training CourseExplore Program
Boost Your Salary 5x in 2024

The nodes are not visible right now because they haven’t been configured, which is what we’ll do in the next step.

all-nodes

So far, we completed this entire process on the master machine, but 

Before moving on, verify the IP of the node machine.

  • Note the IP

  • Return to the workstation

After confirming that you’ve uploaded a sample workbook, the next step is to ensure that a server and node can communicate with each other.

We also use the knife tool for this with the following command:

Boost Your Salary 5x in 2024

Docker Certified Associate Training CourseExplore Program
Boost Your Salary 5x in 2024

knife bootstrap *IP address of your node*

Logging in there will use the node as the root user. The root password for the node also needs to be specified, and the node needs to be named. This is how you will identify the node on the server.

In this demo, we are using the term SSH, which is a secure shell. This provides a secure communication channel between the two machines in the environment.

ssh

After the execution of the command, the Chef server and the Chef node must be able to communicate with each other. If they can, we should be able to send the cookbook from the server to ournode that we had previously uploaded from a Chef Workstation onto the server.

Boost Your Salary 5x in 2024

Docker Certified Associate Training CourseExplore Program
Boost Your Salary 5x in 2024

6. Send the Cookbook From the Server to the Node

After this process is complete, we will return to the Chef server and refresh the page. The node that we wanted to identify should be easy to find. 

The “Nodes” tab, which was initially empty, contains a node named chef_node.

node tab

The node is a CentOS platform, and you can also see the IP address. The uptime states the hours of activation, and the last time a user checked in to this node.

Now, we’ll create a run list and add a sample to it.

  • Click on your node and then the small arrow at the end
  • Click on “Edit Node Run List”
  • Under “Available Recipes,” the sample cookbook is visible
  • Drag that cookbook from the Available Recipes to the Current Run List, and accept it

Now that we have updated the run list, the recipe is sent to the node.

The next required step is executing this at our node.

  • We’ll move on to the node mode machine we created in this demo
  • Then execute the following command:

Boost Your Salary 5x in 2024

Docker Certified Associate Training CourseExplore Program
Boost Your Salary 5x in 2024

chef client

chef-client

Here, you can see everything that is happening.

  • The first line states that the recipe was supposed to install the httpd package, which the Apache server has done—it is up to date
  • The second line states that it is enabled
  • The third line states that the service has started
  • The fourth line is where your content is created for the web page at this very location

Now, the next question that may arise: How can you verify if the entire Chef installation was successful?? 

To verify:

  • Go to the browser and in the search bar, type localhost.

congratulations

If you see a "Congratulations on completing the Chef demo" message, it means that the httpd package, which was the Apache server, is installed. Furthermore, the sample web page is also successfully hosted.

Boost Your Salary 5x in 2024

Docker Certified Associate Training CourseExplore Program
Boost Your Salary 5x in 2024

Conclusion

We hope that our comprehensive guide to the Chef installation was helpful. We discussed Chef’s architecture, including a hands-on demo of the installation process, plus configuration. The six steps we outlined in this article can help users easily and efficiently install Chef.

Do you have any questions for us? Please feel free to ask them in the comments section of our article, and we’ll have our experts answer them for you.

DevOps Professionals Are in High Demand

DevOps is the wave of the future, and Chef is one of the most popular tools used in the field. If you are looking to kickstart your career in this exciting field, check out Simplilearn’s DevOps Certification Training course today! What are you waiting for?

About the Author

Ishan GabaIshan Gaba

Ishan Gaba is a Research Analyst at Simplilearn. He is proficient in Java Programming, Data Structures, and Project Management. Graduated in Information Technology, Ishan is also passionate about writing and traveling.

View More
  • Disclaimer
  • PMP, PMI, PMBOK, CAPM, PgMP, PfMP, ACP, PBA, RMP, SP, OPM3 and the PMI ATP seal are the registered marks of the Project Management Institute, Inc.