Make Your IT Automation Systems Play Together Like a Symphony

Cloud Orchestration with Chef

Orchestration with Chef

Like any other orchestration provider, Chef uses templates, as well as an orchestration infrastructure.

Regardless of the software you use, the first step is to use code to define your particular infrastructure. That means, effectively, creating a “digital twin,” or at least a “coded twin” for each part of your infrastructure that you wish to automate and then orchestrate. Let’s suppose you have an essential resource, such as a Web server with an attached database, as well as a load balancing server that you wish to automate. If this is the case, you’ll need to use some form of markup language to define this resource.

Chef uses the Ruby programming language to define its templates. Chef calls these templates, “Recipes.” Chef uses Python to create these recipes. It calls its Python-specific language “Domain-Specific Language (DSL).” This means you’ll effectively using Ruby, though Chef contains plenty of documentation and even drag and drop/WYSIWYG interfaces to help you understand how to define your infrastructure recipes. You really won’t have to become that much of a Ruby wonk in order to use it.

It is important, though, to understand that these recipes are what allow you to use Chef to first automate tasks, and then orchestrate them so that you can have your Web server, database and load server working properly in your business.

Each of the recipes can be placed into a “cookbook,” which is effectively the domain that I’ve described in Figure 1.

Chef Terminology

Before we continue, it’s important to understand Chef’s vendor-specific terminology. Chef uses the following terms for its architecture:

  • Chef Workstation: The computer you use to configure the orchestration engine, which is called a Chef Server. This is the workstation you’ll use to control the Chef server and type in commands to create recipes so that you can create automated templates to create and provision systems, and then orchestrate those automation templates. You use a Chef “workstation” to “configure recipes” (i.e., templates) and place them into cookbooks.
  • Chef Server: The orchestration engine. It’s the central system, or server that stores all of the automation and orchestration engine information.
  • Chef Node: A server or system that you use to manage with a Chef Server.
Figure 2: Typical Chef infrastructure

Recipe for Apache Server

Now that you understand a bit more about how Chef works, let’s create a template, or “recipe.”

Following is an example of a recipe in Chef for installing and configuring an Apache Web server, which would be the first step in creating your Web server, database and load server:

01 node.default['main']['doc_root'] = "/stanger/web"
02
03 execute "apt-get update" do
04 command "apt-get update"
05 end
06
07 apt_package "apache2" do
08 action :install
09 end
10 service "apache2" do
11 action [ :enable, :start ]
12 end
13
14 directory node['main']['doc_root'] do
15 owner 'www1-data'
16 group 'www1-data'
17 mode '0744'
18 action :create
19 end
20
21 cookbook_file "#{node['main']['doc_root']}/index.html" do
22 source 'index.html'
23 owner 'www1-data'
24 group 'www1-data'
25 action :create
26 end
27
28 template "/etc/apache2/sites-available/111-default.conf" do
29 source "vhost.erb"
30 variables({ :doc_root => node['main']['doc_root'] })
31 action :create
32 notifies :restart, resources(:service => "apache2")
33 end

The above code is relatively self-explanatory. Lines 01 through 09 update apt-get on my Ubuntu system. Lines 1 through 12 start the Apache server. Lines 14 through 26 create the appropriate files and directories. Lines 28 through 30 contain the template information.

You now have a repeatable recipe that you can use for your organization. You would then create a recipe for your database server, as well as your load server.

Now that you have a recipe, let’s learn how to install the Chef client. The Chef client contains the knife utility, which allows you to deploy the recipes you create by creating cookbooks. A cookbook is a directory structure that contains various recipes, or templates. Once you’ve created multiple recipes, you can then orchestrate them into a cookbook. But to do that, you need to use the knife utility, which is part of the Chef workstation client.

Buy ADMIN Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus
Subscribe to our ADMIN Newsletters
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs



Support Our Work

ADMIN content is made possible with support from readers like you. Please consider contributing when you've found an article to be beneficial.

Learn More”>
	</a>

<hr>		    
			</div>
		    		</div>

		<div class=