Chef – Introduction
A system administrator who does everything manually wastes their time. Tasks that a sysadmin performs repeatedly should be automated. Automation through scripting, specialized software and system scheduling saves time and prevents human errors. For automation, there are multiple configuration management tools available in IT industry like Puppet, Ansible, Salt, Chef etc.
What is Chef?
A Chef is a powerful automation platform that transforms infrastructure into code. Whether users are operating in the cloud, on-premises or in a hybrid environment using chef sysadmin can automate how infrastructure is configured, deployed, and managed across their network.
The above diagram [Fig. (1)] shows the relationship between three basic elements of Chef, including the nodes, server, and the workstation. These elements work together to provide the information and instruction to the chef-client that it needs so that it can do its job.
Basic components of Chef:
Chef has its own architecture and a list of components which are the building blocks of the chef platform architecture.Below is the list of main components:
1. Chef Server: Chef Server is the Central component for the Chef Architecture. It is used to store the cookbooks written by any user from a workstation. It has nodes and corresponding information sent by the respective chef-clients. Chef server has chef management console for a user interface. It is used to manage data bags, attributes, run-lists, roles, environments, and cookbooks, and also to configure role-based access for users and groups.
Basic Installation steps for chef server :
- Download the chef-server package from https://downloads.chef.io/chef-server and install package using following command:
- Create a administrator and organisation with following command. These command will also create pem files
2. Chef Workstation: Workstation is used to author, test and maintain cookbooks. It push cookbooks to the chef server and bootstraps the nodes. Cookbooks are uploaded to the Chef server from the workstation. Some cookbooks are custom to the organization and others are based on community cookbooks available from the Chef Supermarket.
Basic installation steps for chef workstation :
- Download chef-dk package from https://downloads.chef.io/chef-dk/ and install package on workstation
3. Chef-client: A chef-client is an agent that runs locally on every node that is under management by Chef. When a chef-client is executed, it will perform all of the steps that are required to bring the node into the expected state.
- Bootstrap chef-client using knife command from workstation.
- Create a chef-repo
To setup chef-repo on workstation, user can download the starter kit from chef-server [Refer Fig. (2)]. The starter kit will create the necessary configuration files — the .chef directory, knife.rb, the ORGANISATION-validator.pem, and USER.pem files with the correct information that is required to interact with the Chef server. Simply download the starter kit and then move it to the desired location on workstation.
Benefits of chef
- Consistency: Make life easier for system administrators by automating repeated tasks. Automating administration tasks with a chef gives consistency in their work.
- Simplified Rebuilding: Automated deployments using a chef help quickly restore service. System administrators can build a new, upgraded system in an automated fashion and throw the old one away, returning it to the server pool.
- Visibility: When infrastructure changes are handled by chef, changes can be automatically logged in all relevant tracking systems to raise visibility on the meaningful work user teams are doing.
- Open-Source: Chef is open source and supported by a vibrant community of system administrators and developers. Chef open source has been used to power products from Dell, from Facebook, and from Amazon Web Services.
Creating a simple LAMP-stack using chef cookbook
- Use this command to create cookbook on workstation
2. It will create a directory structure as shown in Fig. (4)
3. Edit default.rb file [given below] by navigating to recipe directory and add the following ruby command in file.
4. After editing the cookbook recipe, upload it to the chef server.
5. Add this recipe to users node’s run list
6. To run cookbook on node user have to navigate to chef-client machine and then run the chef-client command and LAMP stack will be setup on chef-client machine.
Chef is an automation platform that “turns infrastructure into code”, allowing organizations to generate a process that will save time, effort and make easy to build chef infrastructure. With Chef, user describe users infrastructure as code, which means it can versioned, is human-readable and testable. Using chef it is easy to manage a cloud as well as on-premise client. Chef can manage recipes without any efforts.