Chef is a configuration management tool based on ruby. It is used to automate the management of configurations across all the nodes in the cluster and maintain consistency. There are three major components of Chef.

Chef server Workstation Nodes

All the configurations are managed from workstations and later pushed on to the chef-server. Chef server is the centralized store of all the infrastructure configurations. Knife is a command-line tool present on a workstation that is used to interact with Chef Server. Nodes run chef clients who ask for configuration information from the chef server. This is how a typical Chef architecture looks like:

Now let’s go ahead and setup chef Server, Workstation, and Node (Chef Client).

Environment Details

I am using 3 Ubuntu 18.04 systems. One will act as a chef server, and the next one will be a workstation, and a 3rd system will be the node. Chef Server

Hostname: chef-geekflare IP Address: 192.168.0.107

Workstation

Hostname: workstation IP Address: 192.168.0.108

Node

Hostname: client-node IP Address: 192.168.0.109

Before I begin the installation, I need to edit the /etc/hosts file of all the systems so that they can resolve each other. Edit the /etc/hosts file on all the systems, as shown below. I will run below command on all the three systems to update them.

Chef Server Installation

Chef Server is a component in the architecture that connects Workstation and Nodes. When the configurations are edited/changed on a workstation, they are pushed to the chef-server, and all the nodes pull these configuration changes from the Chef Server. Now, let us run the command below to download the chef-server package. Now you need to run the following command install the chef server. chef-server-ctl is command-line utility in chef-server. I will use this utility to start the chef-server services. You can check the status of the services which have started using the below command.

Create User and Organization

Chef server connects workstation and client nodes. To link them, I will create an admin and organizer with their private keys.  Firstly, create a .chef directory to store the keys. Now, I will use chef-server-ctl to create a user. In the command below, chefadmin is the user, Chef is the first name, GeekFlare is the last name, chefadmin@geekflare.com is the email id, geekflare is the password, chefadmin.pen is the RSA key. Let us run a command to check the list of users on the chef server. Now, I will use chef-server-ctl to create an organization. In the command below, chef-org is the organization name, Geekflare Chef Infrastructure is the full org name, chefadmin is the user we just created., chef-org.pem is the RSA key.  Let us run a command to check the list of organizations on the chef server. I have installed the chef-server completely, let us go ahead and install workstation where all the configurations are created.

Workstation

Workstation is the place where users create cookbooks. Cookbooks are nothing but the configuration units which are created to run specific tasks. Let us run the command below to download the chef workstation package. Let us run dpkg command to install a workstation on the ubuntu system. I will now run a command to create a chef repository that will have all the cookbooks and other files. Now I will create /chef-repo/.chef directory, which will store all the knife configurations and the RSA keys. Now let us generate RSA key-pair. We are generating this key to authenticate the workstation and get access to the chef server. Now copy the key to the chef-server from the workstation. Now I will copy the .pem files (chefadmin.pem and chef-org.pem) from the chef server to the workstation. Check if .pem files got copied successfully on the workstation.

Create Version Control

While working on a workstation, a lot of changes and editing happens in cookbooks (configuration units), so a version control system is required to keep track of these changes. So, let us go ahead and create a version control system using Git on the workstation. I will create a git repository inside the chef-repo directory. I will add a username and email to configure git Let us add the .chef directory to the .gitignore file. Now I will run add and commit git commands from a chef-repo directory. Check the status.

Generate Your First CookBook

Now the installation of WorkStation is complete, and you can start creating cookbooks on the WorkStation. Try generating a sample cookbook on the WorkStation and see if it gets generated successfully. I will run the below command to generate a cookbook. Generate chef-repo, then move to a chef-repo directory

Configure Knife

Knife is a command-line tool to manage nodes, cookbooks, and recipes. To configure Knife, create a config.rb file and put the below content in the file, these are knife configurations. Now go to a chef-repo directory and copy SSL certificates. To check that config.rb is set correctly, run the command below.

Bootstrap a Node

Bootstrap runs from the workstation machine and installs the chef-client on the nodes. The nodes can then read configurations from the chef server by using the client node’s user and password to bootstrap a node. I will now bootstrap a node with IP address 192.168.0.109, user name geekflare, and password geekflare.org. I will now list all the nodes which got bootstrapped Run below command to get the details of the node. Now the setup is ready! We have successfully installed a chef server, workstation, and a node on Ubuntu. You can go ahead and start creating recipes and cookbooks in Chef for configuration management of infrastructure. If you are an absolute beginner, then you may like taking this Udemy course too.

How To Install Chef On Ubuntu 18  - 33How To Install Chef On Ubuntu 18  - 63How To Install Chef On Ubuntu 18  - 74How To Install Chef On Ubuntu 18  - 34How To Install Chef On Ubuntu 18  - 30How To Install Chef On Ubuntu 18  - 65How To Install Chef On Ubuntu 18  - 56