The Complete Magazine on Open Source

All About a Configuration Management Tool Called Chef

, / 337 0
Explore Chef, the open source tool that streamlines the task of configuring and maintaining a company’s servers. Written in Ruby and Erlang, it can easily integrate with cloud-based platforms to automatically provision and configure new machines.

Chef is an open source tool and framework that provides developers and systems administrators a foundation of APIs and libraries, which are used to perform tasks such as configuring and managing IT infrastructures. The concept behind using framework technology is to reduce development time by minimising the overhead of implementing and managing the low-level details that support the development effort. This enables organisations to concentrate on delivery and meeting the customers’ requirements.
Chef is a framework for infrastructure development, which provides a supporting structure and package for framing one’s infrastructure as code. It provides extensive libraries for building up an infrastructure that can be deployed within a software project. It provides a Ruby-based DSL modelling infrastructure, which enables developers and systems administrators to build and design scalable environments without considering the operating systems. It produces consistent, shareable and reusable components.
Chef provides various tools built on the framework for designing the infrastructure. These tools are based on high level programming languages such as Python and Ruby. Some of the tools are:
1) Ohai, a system profiling tool, which is an extendable plug-in to furnish the data that is used to build up the database of each system that is managed by Chef.
2) Shef, an interactive debugging console for testing and exploring Chef’s behaviour in various conditions. It provides command line access to framework libraries.
3) Chef-Solo, a configuration management tool, which allows access to subsets of Chef’s features.
4) Chef Client, an agent that runs on the system managed by Chef to communicate with the Chef server.
5) Knife, a multi-purpose command line tool, which provides system automation, integration, and deployment.

A Few features of Chef

  • It manages a huge amount of nodes on a single Chef server.
  • It maintains a blueprint of the entire infrastructure.
  • It can be easily managed using operating systems such as Linux, Windows, FreeBSD and Solaris.
  • It integrates with all major cloud service providers.
  • High availability.
  • Centralised management, i.e., a single Chef server can be used as the centre for deploying the policies.
  • It provides a Web-based management console to control the access of objects such as nodes, cookbooks and so on.
Figure 1 How Chef Works with AWS Nodes

Figure 1: How Chef Works with AWS Nodes

How Chef works

Chef converts infrastructure into code. Whatever operations can be done with the code, can be done with the infrastructure as well. Yes, it is possible to keep infrastructure versions, test them and create infrastructure repeatedly and efficiently.
A resource is a definition of an action that can be taken such as the installation of a package, Web server or application server; or managing a configuration file. Chef uses reusable components known as recipes to automate infrastructure. A recipe is a collection of resources that includes packages, templates and so on. A cookbook is a set of recipes such as the installation of the Web server, the database server, and configuration file changes to connect the Web and database servers in different deployment environments. A workstation is the place where the Knife is configured to upload cookbooks to the Chef server. Chef’s command-line tool, Knife, is used to interact with the Chef server and upload cookbooks. Attributes provide specific details of a node, such as the IP address and other configuration details.

The Chef server is the central registry or brain of the entire process and can act as a hub. It consists of information about the infrastructure and cookbooks. The latter are used to instruct Chef on how each node must be configured. The Chef server can be either hosted on-premise, on the cloud or be offered by some service provider as well. It is used to deploy cookbooks to the nodes. There is an option of signing up for Opscode’s Hosted Chef. Each node is registered with the Chef server, which distributes cookbooks to the nodes based on different configuration settings.

The Chef client is installed on the nodes; it contacts the Chef server, fetches cookbooks and executes them on nodes. The Chef client does the actual configuration. It polls the Chef server at regular intervals for the most recent recipes, and checks node compliance with the policy defined by the most recent recipes. If the node is out of sync, the Chef client runs the policy on the node to bring it up-to-date. A node can be a physical server, a virtual server or a virtual machine in a private cloud or public cloud environment. Many plug-ins are available for Knife that provide support for cloud-based environments. Amazon EC2, Amazon Virtual Private Cloud, VMware, Google Compute Engine, OpenStack, Rackspace and Microsoft Azure are supported cloud platforms or cloud-based environments. A Chef client is an agent that runs locally on every node hosted in different environments, and follows the steps shown in Figure 2.

Figure 2 Chef Client

Figure 2: The Chef Client

Chef, VMware, AWS and continuous delivery

A Chef and VMware-based private cloud
Chef is the configuration management tool and an automation platform for installing, configuring and managing VMware infrastructure. It can be used to automate the entire stack including provisioning and de-provisioning VMs, templates and networks.

vCloud Air is a public cloud platform built on the foundation of vSphere. It is compatible with the on-premises data centre. It allows organisations to extend workloads into the cloud or to migrate existing onsite virtual machines to the public cloud. Chef can be used to automate migrations to vCloud Air. Chef has the capability of provisioning new vCloud Air VMs and bootstrap, as well as list the vCloud Air VMs, vApps, templates or images, networks, NAT rules, firewall rules and public IP addresses.

VMware vCenter Server is a centralised management tool to manage virtualisation environments based on VMware vSphere. It can be used to manage multiple ESXi servers and virtual machines with a single console application. It provides enterprise level features such as high availability and fault tolerance with VMotion, Storage VMotion and Distributed Resource Scheduler. The knife-esx plug-in gives you full control of ESX-hosted virtual machines. Chef’s knife-vsphere plug-in is used to provision and manage VMs with VMware vCenter. The knife-vsphere plug-in can be used to list data stores, resource pools and clusters; to list, clone, and delete VMs; perform specific actions by executing commands on deployed virtual machines; to customise or reconfigure vCPUs, VRAM, and IP addresses to clone a VM; and to clone and bootstrap Linux VMs and Windows VMs.

Figure 3 Chef Plug-in for VMware

Figure 3: Chef Plug-in for VMware

VMware ESXi is an enterprise-level operating system-independent hypervisor offered by VMware. It is a Type 1 hypervisor for guest virtual machines. It runs on a physical host without an underlying operating system support and hence it gives better performance than Type 2 hypervisors. Chef can be used to provision/de-provision or manage virtual machines hosted by ESXi. The knife-esx plug-in is used to integrate Chef with ESXi.

Advantages of Chef in a VMware environment
There are many advantages of using Chef in a VMware environment as listed below:

  • Write once, deploy many times
  • No manual configurations
  • No inconsistencies in environment
  • Standardised run time environment; application deployment, middleware and databases

Chef and the Amazon public cloud
Chef and Amazon public cloud integration makes infrastructure fast and agile. The knife-ec2 plug-in is used to integrate AWS and Chef. It allows cloud consumers to launch and configure EC2 instances, to create base Amazon Machine Images, to register EC2 instances with Elastic Load Balancers, to manage EBS volumes and raid devices. It is very easy to spin off a Windows 2012 server, configure IIS and deploy a .NET app in AWS with the use of Chef, which provides speed and efficiency with standard environments. In AWS, it is very easy to maximise the uptime of the Chef server by taking advantage of Chef’s integration with Amazon’s elastic block storage and elastic IPs. Different AWS regions can also be used to gain high availability.

Comparisons between Chef and Puppet
Here’s a comparison of two configuration management tools—Chef and Puppet, which will enable you to take an informed decision based on the needs and expertise your organisation has in using Chef or Puppet.