In this chapter, we’ll walk you through the process of installing and configuring all the tools necessary to write Chef automation code. The setup covered is all you need for the hands-on exercises in this book. Linux, Mac OS X, and Windows are all first-class, supported development environments by Chef Software. We’ll cover all these environments in this book, noting the platform-specific differences as necessary.
Install a Programmer’s Text Editor
To write Chef code, you must use an editor designed to save files in raw text format. Do not use Microsoft Word, or a similar editor that saves text in a different file format, as Chef will have difficulty reading your files. Make sure that you have either a command line text editor or GUI text editor handy.
If you are comfortable using command line editors,
vim
, GNU Emacs, or nano
are popular choices. Since it is difficult to perform system administration duties without a command line editor, we assume you have already configured one on your system.
If a text editor with a graphical user interface is more to your liking, we recommend Sublime Text. All the platforms covered in this book are supported by the Sublime Text editor—Linux, Mac OS X, and Windows. In addition to providing syntax highlighting and line numbers, Sublime Text also supports a project view for navigating through directory hierarchies as shown in Figure 2-1. You will find all these features handy as you write Chef code:
- Line number display
- Highlighted syntax
- Command autocomplete
- Ability to have multiple files open at once
Sublime Text offers some excellent plugins for writing Chef code as well. Sublime Text costs $70. We recommend giving Sublime Text a trial spin as you follow the coding examples in this book.
If Sublime Text isn’t the right GUI editor for you, some other free alternatives to consider would be gedit for Linux, TextMate 2 for Mac OS X, and Notepad++ for Windows.
NOTE
Although there are currently no integrated development environments (IDEs) for Chef, Ruby IDEs work well with Chef—RubyMine, IntelliJ IDEA, Eclipse to name a few. A Ruby IDE will include a programmer’s text editor as well.
Also, JetBrains supports Chef in its RubyMine and IntelliJ IDEs.
Chef Development Tools
The Chef Development Kit includes all the basic tools you need to get started writing Chef code. In the following sections we’ll cover how to install the Chef Development Kit on Linux, Mac OS X, and Windows. Follow the applicable section that matches the operating system on your computer.
All Chef development tools are written in Ruby, a popular scripting language. The use of a scripting language eliminates the need to write and maintain native code individually for Linux, Mac OS X, and Windows. Instead, a single set of Ruby scripts implements the Chef development tools on these three supported platforms. For the scripts to function, you must install a native Ruby scripting engine to run the Chef development tools.
The Chef Development Kit installer for each platform comes bundled with the correct native Ruby scripting engine. The Chef development tools and the Ruby scripting engine are installed outside any commonly used system locations. This ensures that the Ruby bundled with Chef will not interfere with another copy of Ruby used elsewhere on your system.
As of this writing, the Chef Development Kit is relatively new and supports only recent versions of Linux, Mac OS X, and Windows. If you happen to be using an operating system version that isn’t currently supported by the Chef Development Kit, you’ll find additional instructions showing you how to manually install the extra development tools you’ll need after installing Chef Client.
Skip ahead to the installation section for your operating system of choice:
Install the Chef Development Tools on Linux
You will need an Internet connection and root access on your computer in order to install the Chef development tools on Linux.
Visit the Chef downloads page to download the installation package for your distribution of Linux.
Follow the Chef Development Kit link as shown in Figure 2-2 to see if there is an installation package available for your platform.
Figure 2-3 shows the options available for Linux as of this writing. Choose your desired distribution and version of Linux. Once you’ve made your selection, a download link for an installation package will be displayed.
If there is no Chef Development Kit installer for your preferred version of Linux, you’ll need to install the Chef Client for your platform instead and perform some additional steps manually. Using the Chef Development Kit installer is preferred because it makes installation more convenient, but it is not necessary. Go back to the main page and install the Chef Client instead.
On the Downloads page, under Chef Client, select the distribution and version of Linux installed on your computer as shown in Figure 2-4. Once you’ve made these selections, a download link for an installation package will be displayed.
The details for the installation process will vary by Linux distribution. Refer to the web page for more specific instructions. You will get a link to an installation package or a script.
NOTE
The download page might not match the images in this book exactly. The download and installation procedure, however, should be the same.
For RedHat/CentOS and other Enterprise Linux variants, open your terminal and use
rpm
to install with a command prompt. As an example, if the installation package link was chefdk-0.2.0-2.el6.x86_64.rpm
, you would enter in the following, replacing the last parameter with the package name from either the Chef Development Kit or Chef Client download link you just visited:
For Ubuntu/Debian distributions, open your terminal and use
dpkg
to install with a command prompt. As an example, if the installation package link was chefdk_0.2.0-2_amd64.deb
, you would enter the following, replacing the last parameter with the package name from the Chef Development Kit or Chef Client download link you visited:
The Chef Development Kit installer will automatically install Chef and Ruby in the /opt/chefdk/embeddeddirectory on your local machine. Neither of these directories are commonly present in the default environment’s
PATH
.
The Chef Development Kit includes a
chef shell-init
command to modify the current shell environment to use these paths. Assuming you are using the Linux default bash
shell, run the following command to permanently enable this PATH setting:
Chef Development Kit installation:
If it was necessary to choose the Chef Client installation instead, the Chef and Ruby installation will be located under /opt/chef/embedded.
We recommend you add this
bin
location to the following PATH
. You should add this line to your $HOME/.bash_profile
(or similar *.profile
if you are using a different command line shell).
Chef Client installation:
Once you change
$HOME/.bash_profile
, you will need to source
the file to set up the correct $PATH
. Alternatively, you can just close and open your terminal application to reload $HOME/.bash_profile
.VERIFY THE CHEF DEVELOPMENT KIT/CHEF CLIENT INSTALL ON LINUX
Make sure the Ruby scripting engine in either /opt/chefdk/embedded/bin or /opt/chef/embedded/bin is being used with this
$PATH
change, depending on whether you installed the Chef Development Kit or the Chef Client, respectively. Enter which ruby
in a terminal or command prompt. You should see the following:
Chef Development Kit installation:
Chef Client installation:
If you see no output at all, or if the output is not
/opt/chefdk/embedded/bin/ruby
or /opt/chef/embedded/bin/ruby
, double-check that you have completed the preceding steps correctly.NOTE
If you do not want to change your
$PATH
, you could specify the full path to each embedded binary on the command line, such as
Going forward, so the command line entries fit better on our printed pages, this book will assume that you modified your
PATH
.
Verify that the basic Chef tools are present by checking /opt/chefdk/bin or /opt/chef/bin depending on whether you installed the Chef Development Kit or the Chef Client, respectively. You should see the following with the Chef Development Kit installation:
and with the Chef Client installation:
Run
chef-client --version
to ensure the chef-client
command works properly. If your version differs, make sure that you have chef-client
version 11.10.0 or higher to follow the hands-on exercises in this book:
If you installed the Chef Development Kit, you have now successfully installed the Chef development tools on Linux. Skip ahead to Summary. If you installed the Chef Client, you’ll need to perform a few more installation steps, so keep reading.
INSTALL TEST KITCHEN ON LINUX (CHEF CLIENT ONLY)
We’ll be using Test Kitchen to create virtualized sandbox environments in some of the hands-on exercise. The Chef Client installer does not install Test Kitchen, so you’ll need to install it manually.
You need to install the
test-kitchen
gem. A gem is a supporting library or application written in Ruby. You can think of a gem as the equivalent of an installer for Ruby. Rubygems.org maintains a central registry of Ruby gems on the Internet.
Run the
gem install
command as root to install the test-kitchen
gem. The additional --no-ri
and --no-rdoc
parameters save time by omitting the step that generates documentation:VERIFY THE TEST KITCHEN INSTALLATION ON LINUX (CHEF CLIENT ONLY)
You can verify that the
test-kitchen
gem is installed by using the gem list
command. If Test Kitchen is already installed, the gem list
command will display the output true
:
You have now successfully installed the additional tools on Linux needed to follow the hands-on exercises in this book. Skip ahead to Summary.
Install the Chef Development Tools on Mac OS X
You will need an Internet connection and administrator privileges in order to install the Chef development tools on Mac OS X.
Visit the Chef downloads page to download the installer for your version of Mac OS X.
Follow the Chef Development Kit link as shown in Figure 2-5 to see if there is an installation package available for your version of Mac OS X.
Figure 2-6 shows the options available for Mac OS X at the time of this writing. Currently, only the most recent version of Mac OS X, Mavericks (10.9), is supported, and not older versions like Mountain Lion (10.8) or Lion (10.8). When you click on the download link, an installation package will be displayed.
If there is no Chef Development Kit installation for your preferred version of Mac OS X, you’ll need to install the Chef Client instead and perform some additional installation steps manually. Using the Chef Development Kit installation is preferred because it makes the installation more convenient, but it is not necessary. Go back to the main page and install the Chef Client instead.
On the installation page, under Chef Client, choose the version of Mac OS X installed on your computer as shown in Figure 2-7. Once you’ve made your selection, a download link to a Mac OS X disk image .dmg file will be displayed.
NOTE
The download page might not match the images in this book exactly. The download and installation procedure, however, should be the same.
When you open the install .dmg file, you will see an icon with the Chef installation package as shown in Figure 2-8. Double-click on
chef.pkg
to run the installer.
Choose the default options and accept the license as you progress through the Chef Client installation. You might be prompted to enter your password. You’ll need administrator privileges in order to make the necessary changes to run Chef on your machine.
NOTE
Don’t forget to eject the Chef Client disk image once you have completed the installation.
The Chef Development Kit installer will automatically install Chef and Ruby in the /opt/chefdk/embeddeddirectory on your local machine. Neither of these directories are commonly present in the default environment’s
PATH
.
The Chef Development Kit includes a
chef shell-init
command to modify the current shell environment to use these paths. Assuming you are using the Mac OS X default bash
shell, run the following command to permanently enable this PATH setting.
Chef Development Kit installation:
If it was necessary to choose the Chef Client installation instead, the Chef and Ruby install will be located under /opt/chef/embedded.
We recommend that you add this
bin
location to the following PATH
. You should add this line to your $HOME/.bash_profile
(or similar profile file with your startup configuration and settings, if you are using a different command line shell).
Chef Client installation:
Once you change
$HOME/.bash_profile
, you will need to source
the file to set up the correct $PATH
. Alternatively, you can just close and open your terminal application to reload $HOME/.bash_profile
:VERIFY THE CHEF DEVELOPMENT KIT/CHEF CLIENT INSTALLATION ON MAC OS X
Make sure the Ruby scripting engine in either /opt/chefdk/embedded/bin or /opt/chef/embedded/bin is being used with this
PATH
change. Enter which ruby
on a command line. You should see the following with the Chef Development Kit installation:
or, with the Chef Client installation:
If you see no output at all, or if the output is not
/opt/chefdk/embedded/bin/ruby
or /opt/chef/embedded/bin/ruby
, double-check that you have completed the preceding steps correctly.NOTE
If you do not want to change your
$PATH
, you could specify the full path to each embedded binary on the command line, such as
Going forward, so the command line entries fit better on our printed pages, this book will assume that you modified your
$PATH
.
Verify that the basic Chef Client tools are present by checking /opt/chefdk/bin or /opt/chef/bin depending on whether you installed the Chef Development Kit or the Chef Client. You should see the following with the Chef Development Kit installation:
and with the Chef Client installation:
Run
chef-client --version
to ensure the chef-client
command works properly. If your version differs, make sure that you have chef-client
version 11.10.0, or higher to follow the hands-on exercises in this book:
If you installed the Chef Development Kit, you have now successfully installed the Chef development tools on Mac OS X. Skip ahead to Summary. If you installed the Chef Client, you’ll need to perform a few more installation steps, so keep reading.
INSTALL TEST KITCHEN ON MAC OS X (CHEF CLIENT ONLY)
for some of the hands-on exercises. The Chef Client installer does not install Test Kitchen, so you’ll need to install it manually.
You need to install the
test-kitchen
gem. A gem is a supporting library or application written in Ruby. You can think of a gem as the equivalent of an installer for Ruby. Rubygems.org maintains a central registry of Ruby gems on the Internet.
Run the
gem install
command as root to install the test-kitchen
gem. The additional --no-ri
and --no-rdoc
parameters save time by omitting the step that generates documentation:VERIFY THE TEST KITCHEN INSTALLATION ON MAC OS X (CHEF CLIENT ONLY)
You can verify that the
test-kitchen
gem is installed by using the gem list
command. If Test Kitchen is already installed, the gem list
command will display the output true
:
You have now successfully installed the additional tools on Mac OS X needed to follow the hands-on exercises in this book. Skip ahead to Summary.
Install the Chef Development Tools on Windows
You will need an Internet connection and administrator privileges on your computer in order to install the Chef development tools in Windows.
Visit the Chef downloads page to download the installer for your version of Windows. Follow the Chef Development Kit link as shown in Figure 2-9 to see if there is an installer available for your version of Windows.
Choose your desired version of Windows. Once you’ve made your selection, a download link for an installation package will be displayed.
If there is no Chef Development Kit installation for your version of Windows, you’ll need to install the Chef Client for your platform instead and perform some additional installation steps manually. Using the Chef Development Kit installation is preferred because it makes the installation more convenient, but it is not necessary. Go back to the main page and install the Chef Client instead.
On the installation page, under Chef Client choose the version of Windows installed on your computer as shown in Figure 2-10. Once you’ve made your selection, a download link to the corresponding Windows installer .msifile will be displayed.
NOTE
The download page might not match the images in this book exactly. The download and installation procedure, however, should be the same.
Run the installer for either the Chef Development Kit or the Chef Client, choosing the default options. The Chef Development Kit installer will install Chef and Ruby in the C:\opscode\chefdk directory on your local machine. If it was necessary to choose the Chef Client installer instead, the Chef and Ruby installer will be located under C:\opscode\chef. Either installer will automatically add all the correct directories for Chef and Ruby to the System
PATH
.VERIFY THE CHEF DEVELOPMENT KIT/CHEF CLIENT INSTALLER IN WINDOWS
Make sure that the Ruby scripting engine in either C:\opscode\chefdk\embedded\bin or C:\opscode\chef\embedded\bin is being used with this
PATH
change, depending on whether you installed the Chef Development Kit or the Chef Client, respectively. Make sure you restart your command prompt after the installation and run the appropriate commands to verify.
Chef Development Kit installation—Windows Command Prompt:
Chef Development Kit installation—Windows PowerShell:
Chef Client installation—Windows Command Prompt:
Chef Client installation—Windows PowerShell:
If the output is not
C:\opscode\chefdk\embedded\bin\ruby.exe
or C:\opscode\chef\embedded\bin\ruby.exe
, double-check that you completed the preceding steps correctly.
Verify that the basic Chef client tools are present by checking either C:\opscode\chefdk\bin as shown in Figure 2-11 or C:\opscode\chef\bin as shown in Figure 2-12.
Run
chef-client --version
to ensure the chef-client
command works properly. If your version differs, make sure that you have chef-client
version 11.10.0 or higher to follow the hands-on exercises in this book:
If you installed the Chef Development Kit, you have now successfully installed the Chef development tools in Windows. Skip ahead to Install Unix Tools for Windows. If you installed the Chef Client, you’ll need to perform a few more installation steps, so keep reading.
INSTALL TEST KITCHEN IN WINDOWS (CHEF CLIENT ONLY)
We’ll be using Test Kitchen to create virtualized sandbox environments in some of the hands-on exercises. The Chef Client installer does not install Test Kitchen, so you’ll need to install it manually.
You need to install the
test-kitchen
gem. A gem is a supporting library or application written in Ruby. You can think of a gem as the equivalent of an installer for Ruby. Rubygems.org maintains a central registry of Ruby gems on the Internet.
In Windows, you’ll need to install the Test Kitchen gem as an administrator. Run
gem install test-kitchen
as Run As Administrator or Command Prompt (Admin), depending on your version of Windows. The additional --no-ri
and --no-rdoc
parameters save time by omitting the step that generates documentation:VERIFY THE TEST KITCHEN INSTALLER IN WINDOWS (CHEF CLIENT ONLY)
You can verify that the
test-kitchen
gem is installed by using the gem list
command. If Test Kitchen is already installed, the gem list
command will display the output true
:
You have now successfully installed the additional tools in Windows needed to follow the hands-on exercises in this book.
INSTALL UNIX TOOLS FOR WINDOWS
You’ll need to install Unix-related tools in Windows for Test Kitchen. Test Kitchen requires the Secure Shell
ssh
to log in to your Enterprise Linux VM. The most painless way to install ssh
is to install the Minimalist GNU for Windows (MinGW) tools that come bundled with Git for Windows. If you use Chef, you’ll likely wind up using Git source control in some fashion as well.
Visit git-scm.com and refer to the git-scm.com site for more information on installing Git for Windows.
Make sure you choose Run Git and included Unix tools from the Windows Command Prompt when you see the Adjusting your PATH environment screen as shown in Figure 2-13. Except for this screen, feel free to choose the installation defaults if you like.
Verify that
ssh
is installed correctly by running ssh
on the command line. You should see a usage screen resembling the following:INSTALL CONEMU (OPTIONAL)
Some of the tools included with Chef Client, such as Test Kitchen, use color in their output, as shown in Figure 2-14.
Neither the Command Prompt nor Windows PowerShell support the mechanism used by the Chef development tools to display text in color. We recommend you install a third-party terminal program for Windows that supports ANSI text color output.
We recommend ConEmu, as not only does it support colored text, but it also greatly improves the command prompt experience in Windows. ConEmu adds tabs, support for full screen, and a plethora of customization options. ConEmu also supports all the Windows command shells, so you can still use
cmd.exe
, PowerShell, bash, or another favorite. ConEmu does not replace existing Windows shells; it merely enhances their capabilities by providing user interface enhancements, such as adding support for color.
To install ConEmu, go to the primary download site for ConEmu and download a ConEmu Installer, as shown in Figure 2-15.
By default, ConEmu will use the
cmd.exe
shell, but you are not limited to this choice. Click on the New console dialog dropdown to choose from other shells, such as PowerShell, as shown in Figure 2-16.
To change the default shell, change the ConEmu settings (see Figure 2-17):
- Click on the icon in the upper-left corner to display the application menu.
- Choose Settings to display the Settings dialog.
- In the settings dialog, choose Startup from the tree.
- Choose your desired default shell from the pulldown under Specified named task.
- Click on the Save settings button to make the setting your default.
Summary
Now that you have installed the Chef development tools on your computer using either the Chef Development Kit installer or the Chef Client installer, you have all the basic tools you need to interact with Chef. For some environments, there is no Chef Development Kit available, so we walked you through the manual steps necessary to make a Chef Client installation equivalent to a Chef Development Kit installation, for the purposes of this book. The Chef Development Kit is a superset of the Chef Client, with some additional community tools bundled with the installer. You can install these extra tools by hand if there is not yet a Chef Development Kit available for your platform.
Before we delve more deeply into Chef, in the next chapter we’ll take a brief, related detour covering just enough Ruby to get started with Chef. Chef is based on Ruby, so you have to know a little bit of Ruby to get started with Chef.
This is a great way for a simple quick start with Chef, Installation steps are very easy to follow up. Thanks for sharing very simple procedure to set up Chef.
ReplyDeleteBest Regards,
DevOps Training in Hyderabad
DevOps Online Training in Hyderabad
DevOps Online Training
DevOps Institutes in Hyderabad
Learn DevOps Online
Best DevOps Training Institute in Hyderabad
Best DevOps Online Training Institute in Hyderabad
Best DevOps Online Training in India
DevOps Institute in Hyderabad
Best DevOps Training
DevOps Training and Certification
learn DevOps
DevOps Institutes in Ameerpet
DevOps Training
DevOps Courses
DevOps Certification Training
CourseIng
Really Good blog post.provided a helpful information.I hope that you will post more updates like this Ruby on Rails Online Training Bangalore
ReplyDeletewell! Thanks for providing a good stuff related to DevOps Explination is good, nice Article
ReplyDeleteanyone want to learn advance devops tools or devops online training
DevOps Online Training
DevOps Online Training hyderabad
DevOps Training
DevOps Training institute in Ameerpet
DevOps Training in Ameerpet
DevOps Training institute in Hyderabad
DevOps Course in Hyderabad
I like your post very much. It is very much useful for my research. I hope you to share more info about this. Keep posting!!
ReplyDeleteBest Devops Training Institute
thanks.Quality posts is the crucial to invite the visitors to visit the web page, that's what this web page is providing.
ReplyDeleteDevOps Training in Bangalore | Certification | Online Training Course institute | DevOps Training in Hyderabad | Certification | Online Training Course institute | DevOps Training in Coimbatore | Certification | Online Training Course institute | DevOps Online Training | Certification | Devops Training Online
Actually I read it yesterday but I had some thoughts about it and today I wanted to read it again because it is very well written.
ReplyDeleteSalesforce Training in Chennai
Salesforce Online Training in Chennai
Salesforce Training in Bangalore
Salesforce Training in Hyderabad
Salesforce training in ameerpet
Salesforce Training in Pune
Salesforce Online Training
Salesforce Training