Working with Chef for server configurations

Chef is one the intresting server configuration management tool written in Ruby and Erlang. It uses a pure-Ruby, domain-specific language for writing system configuration.

The most important part of Chef is “Chef-Server” and “Chef-Client” few of the people are still using “Chef-Solo” but it’s too old to use.

Let’s learn about it one by one.

Chef-Server

Chef-Server works as a centralized server provided by Opscode ( Chef ) to the client and it’s free of cost, but for enterprise services, you need to purchase their license.

Visit the link https://www.chef.io/account/login and signup there.

Once you will verify the link in your mail, you’r ready to proceed.

Just login with your credentials and create your organization.

Once it will be created you will be able to see the dashboard which is going to be dedicated to organization.

You will be able to create as many of organisation you required for chefing and bootstraping the instances.

Below is the dashboard of Chef.

Now, the next step is to register your instances or Server with centrally managed Chef Server.

So for that, you need to download the “Starter Kit” from Chef server itself by clicking on Administration —> Select your Organization –> Starter Kit .

Extract the zip file and locate to the directory named “chef-repo”.

It contains all the important configuration and directory from where you can begin with.

Cookbooks

It contains your logic and codes for chefing the server.

Attributes

The place where your variable are going to exist.

Recipes

All the logics of configuring your server will exist here only.

Templates

The place where your configuration files exist, like nginx.conf or gunicorn.conf which you want to directly copy on the certain server, it’s just like Files.

Metadata.rb

It’s the most important file for version control on your node server as per the environment like Production, Staging, and Development.

Roles

Roles contains certain task from recipes which will run according to user calls from node as it contains the “run_lists”.

Now, you just need to bootstrap the node server from the “chef-repo” directory with below command from your local machine,

It will install the “chef-client” on the node server and at the same time, your node server will get automatically registered on centrally managed Chef-Server.

Chef-Client

Chef-Client works like an agent and always reside on your node server for communicating with chef-server where your all configuration files will exist.

You first need to upload your created cookbooks with recipes on chef-server, for that run the below command.

Now it’s time to run chef-client on node server from your localhost to bootstrap the instance with your recipes you have defined by using below command.

It will install the apache and it’s configuration on node server.

Chef-Solo

Chef-solo is the oldest version of chef-client and it doesn’t require any chef-server for Chefing your node, it’s a traditional way of copying your cookbook on node server the way SCP command do, and then running the chef-solo command as below.

That’s it for now, I will try to cover all directory structure and configuration in coming blogs, as it will take more than three to four blogs to complete the production-ready deployment in chef.

Leave a Reply