Information Technology Reference
In-Depth Information
string in double quotes (“”) or single quotes (''). For example, use the following
file
re-
source syntax, to specify the filename
/usr/local/hello.txt
:
file
"/usr/local/hello.txt"
It doesn't matter whether you use double or single quotes for string literals; either choice is
valid:
file
'/usr/local/hello.txt'
Now, what is that
do
clause at the end of the first line? The
do
statement at the end of the
first line denotes the start of a
block
. To specify extra parameters in a resource statement, it
must span multiple lines. When resource statements span multiple lines, everything but the
first line must be enclosed by a
do..end
pair. The
do
…
end
pair containing the extra lines is
referred to as a
block
.
Line two contains a reference to a
content
attribute
, specifying a string that should be writ-
ten to the file:
content
'Welcome to Chef'
For now, just think of an
attribute
as yet another variable maintained by Chef that can be
convention, statements in Chef recipes are indented with spaces when they are inside a
block. Thus, the
content
attribute is indented two spaces, following Ruby convention.
The string
Welcome to Chef
is passed as a
content
attribute to the
file
resource. The
file
resource writes out the specified
content
string attribute to the
hello.txt
file.
Finally, line three completes the block for the
file
resource with an
end
statement, finishing
off the
do..end
pair:
end
This example should give you an idea of what Chef code looks like, building on the intro-