📜 ⬆️ ⬇️

Chef for 21 days. Part one. Introduction

Hi, Habrayuzer! On the street, the weather is nasty, sore throat doesn’t give rest to my sore throat, why not write an article? This is my first attempt at writing on Habré, so do not judge strictly. Its name is inspired by a huge number of books with a similar name. In this article I will try to describe the path of the automaton-warrior for young padovans, whom in some measure I myself am. It will be a question of an approach that, with a certain effort, will help in a short time to get acquainted with such a tool of cross-platform automation as CHEF . And also, with a strong effort - to master him sufficiently for the first serious experiments. This article is a kind of “guiding way” for people who are not familiar with the automation process.


Step 1. Discovering CHEF



What is Chef? This is a tool for automated configuration management of your computers (“nodes” in Chef terminology). Nodes communicate with the server, which contains descriptions of actions that must be performed by the node. These actions are described in a cookbook , the main parts of which are recipes (a set of actions for a node), attributes (node ​​data described in json format) and templates (embedded ruby ​​files generated on the node).
')

Step 2. Preparing the environment



Well, what kind of study without fighting? What is needed? The minimum set (sufficient for most cases) is 2 virtual machines with network support. On one of them is installed server ( open source Chef ). The other will be the customer. The choice of OS is arbitrary - the more sophisticated your choice, the more features (in common people with crutches) you will meet. At the moment, my humble experience shows that the most reliable option is Deb-like distributions.

Another option is to use the preview.opscode.com resource, a ready-made Chef server, where you can register yourself and start an organization with a unique name, which you will later add your nodes and cookbook to . After setting up an account and creating an organization - you can download the so-called “start kit” - a ready-made configuration for a chef-administrator containing certificates and configuration files. This kit will allow you to manage the server from your PC.

Step 3. Adding Nodes



The environment is ready, you can add our first nodes. There are two basic ways - you can use the web-interface of the server, or you can use the chef-administrator console . Using the web interface is not our methods, so we will use the console. A toolkit that will help us in this process is knife . It allows you to create a cookbook , add nodes, manage lists of execution for each node, and has many other features. The process of adding a node in this case is called bootstrap , which is essentially the installation and initial launch of the chef client on the node. Also in this process, you can pass the parameters of the first run for the node being created in the form of json-attributes . To perform this operation, you must have access to the administrator account and specify the settings for it. After successful completion of this process - the node appears in the list of available on the node. This list can be viewed through the web-interface or use the knife node directive in the console.

This is where the primary part of the installation process ends, and with happy faces we can go and drink coffee. We gain strength and move on to the most interesting, namely, what is the manifestation of automation.

Step 4. What do we automate?



You ask - these are all the torments of adding nodes that are not at all like automation, because you have to do everything with your hands. Yes, you are right, but there is one "but . " I'm not telling you everything, my young padovan. In fact, this process can also be automated. Let's do a little lyrical digression.

When we have a park of computers, and we carry out the initial installation of the OS on them, we can also install there both our servers and clients. Thus, the first step in installing the software will be implemented. This means that our chef servers and clients are already running and are awaiting instructions (how to make them work like demons or services all the time is a matter of another article). Also, our excellent toolbox knife allows us to search for parameters ( attributes ) of clients. This can be used to conduct some initial actions with the client (for example, to install a particular package). The attributes themselves, if you remember, are assigned when the client is installed using a json file. Attributes, in fact, imagine a label consisting of name and value (yes, everything is extremely simple, as in all automation, ha ha). As a result, we get nodes that are identified by these tags, for example: node1 ("label1" = "value1") . When a server searches for sites, we can set it to search for it — an attribute, and the value to which it should correspond. To be extremely detailed, this can be done using knife exec and nodes.find , but you can read about this separately (links to useful materials will be at the end of the article). So, the search process will give us a list of nodes that meet the criterion, and with this list we can do anything - feed it to the server, which will give the nodes a command to install something according to the recipes, save it, etc.
After all these simple manipulations - we need to get an architecture in which there will be a server and the required number of nodes registered on it and communicating with it in a periodic fashion (it should be noted that on the node it is necessary to implement it using available tools such as cron or Windows Services ). Let's return to our task - automation of the node configuration process.

Chef is so powerful that it allows a lot of manipulations with your nodes. I’m not even sure if I know all his possibilities to the full, I’m almost sure that they don’t. All features can be found on the official website of Chef, in the Docs section, but even there, not all are described.
Need to install a dozen packages and dependencies? No problem! Restart services? No problem! Generate a file by template? No question at all! Run commands in console? No problem!

All this is governed by cookbooks and recipes in them. Actually the creation and use of these - is the skill of the Jedi automator. And to achieve mastery, I strongly advise you to become familiar with Ruby and get into the concept of Chef itself. After a few weeks - you will love him, and he will love you and please, only sometimes scaring crutches and bugs.
In my humble opinion, this part will take 2 days . Of course, it all depends on your perseverance - so go ahead and with the songs (s).

Well, and as promised, useful links are attached below.
Official documents and manuals - docs.opscode.com
Install Chef-server (Enterprise) - docs.opscode.com/install_server_oec.html
Installing a Chef server (open source) - docs.opscode.com/install_server.html
Chef Client Installation - docs.opscode.com/install_workstation.html
Knife tool - docs.opscode.com/knife.html
Useful image with knife options - docs.opscode.com/_images/qr_knife_web.png
Cookbook Baseline Information - docs.opscode.com/essentials_cookbooks.html
Detailed information is here - docs.opscode.com/chef_overview.html .

PS Angina takes its toll, so on this I say goodbye to you until the second part of our article, which will be devoted to the basics of "cooking". I am open to criticism, advice and questions. Thanks for attention!

Source: https://habr.com/ru/post/208542/


All Articles