Chef is to use Chef
- getchef.com

Chef is a tool for configuring servers in the Infrastructure as a Code (IaaC) concept.
Personally for me, Chef is, first of all, the ability to store the service architecture in the form of roles, and modify it, avoiding the routine actions to install packages and configuration.
Chef allows you to run any scripts on the server, providing your own syntax to describe them. Cross platform and structured.
It has a fairly high threshold of entry. The reasons are: seemingly confusing terminology and the difference in the use of Chef and Chef solo.
Solo - a simple way for beginners to work with Chef, allows you to manage your configuration without having to have an additional service server, which limits the functionality. However, these restrictions make themselves felt when managing a large fleet of servers.
This article may be called the "Chef outline."
Perhaps the text will be similar to that translated by a prompt, but I think that the terms used in the text should not be translated, I will be glad to know your opinion on this matter.
')
Terms
- knife is a console utility that allows you to execute scripts from a local machine at a remote north. The main tool of this chef.
- recipe - a script executed on the server. It can perform any tasks: from creating directories to installing and configuring Nginx.
- cookbook - a collection of scripts (recipes). There are many ready-made cookbooks (for example, for installing MySQL, etc.) that can be used without getting inside the script.
- role - server role. For example, mysql or nginx. A role can have an arbitrary number of cookbooks. A server can have several roles.
- node - server with the specified IP address.
Using
It's time to put all the terms into a logical chain and understand how Chef is used.
To set up a server, you describe recipes inside cookbooks, and execute them with the utility knife for a node with one or more roles.
And now, practice
You need to have Ruby, and if you don’t have one, then it’s time to install Ruby-lang.orgInstall and configure Nginx on a fresh server.Create a directory, for example chef-test and go to it.
Install the necessary tools for the job: chef, knife-solo and berkshelf.
Berkshelf - cookbook manager, analog bundler
Create a Gemfile file with the following content:
source "https://rubygems.org" gem 'knife-solo' gem 'berkshelf'
Team bundle finish the installation
bundle
In the current directory create the kitchen
knife solo init . berks init .
Add the necessary cookboks to the created Berksfile
cookbook 'nginx'
And download them
berks install
Describe the server configuration (node)
In the nodes directory, create a file and name it as follows:
<server ip address> .jsonFile describes: which scripts (recipes) need to be executed on a given server (node)
{ "nginx": { "version": "1.6.0", "install_method": "source", "default_site_enabled": true, }, "run_list": [ "recipe[nginx]" ] }
run_list indicates exactly which recipes or recipe groups (roles) need to be executed.
In this variant, the recipe from
Nginx cookbook is executed.
Start Chef and enjoy the work of the machine for the person
knife solo bootstrap username@host -i ~/.ssh/ssh_key.pem
The result will be a ready server with a working web server.
If you need to make changes, for example, change the version of Nginx, it is enough to change the configuration in the
node file and execute
knife solo cook username@host -i ~/.ssh/ssh_key.pem
Chef uses only recipes that have been changed, so you can not be afraid of the safety of the server configuration.
I hope this article has helped to overcome the barrier Chef, because more is waiting for you just the joy of ease of use of this great tool.
If you are interested in this topic, in the next article I would like to describe the process of creating a typical infrastructure for rails applications in Amazon AWS.
Chef Alternatives
useful links
We use these tools in the
Staply project.
We will tell about it very soon!
