Information Technology Reference
In-Depth Information
Verify Your First Chef Recipe
Congratulations, you just automated the creation of the
hello.txt
file using Chef!
Verify that your
hello.rb
recipe performed the correct action. Look to see if a
hello.txt
file ex-
ists in the current directory alongside your
hello.rb
file and that it has the correct content:
$
more hello.txt
Welcome to Chef
Examine hello.rb
Let's go over each line in
hello.rb
from
Example 4-1
in more detail, exploring the purpose of
each component. As mentioned earlier, Chef code uses a
domain-specific language
(DSL)
built on top of the Ruby programming language. Having expressions tailored for system ad-
ministration makes Chef code more accessible to beginners. The DSL is also designed to
make you focus more on describing
what
the desired configuration of a machine should be,
rather than
how
it should be accomplished.
Desired configuration
is a concept we'll cover in
more detail in
Recipes Specify Desired Configuration
.
NOTE
Because Chef recipes are code, we recommend that you use some form of source control
to manage your Chef source. It is beyond the scope of this topic to show you how to use
version control to manage source. However, use version control for everything you do
with Chef. Any version control system will do: Git, Subversion, Mercurial, Team Founda-
tion Server, and so on.
The first line of
hello.rb
contains a
file
resource referring to the file
hello.txt
:
file
'hello.txt'
ddo
Remember that
resources
are building blocks that Chef uses to configure things on a system.
The
file
resource is used to manage a file on a computer. The
file
resource takes a string
parameter specifying the path to the file. In a Chef recipe, this is denoted by enclosing the