Information Technology Reference
In-Depth Information
Add some Chef code to change the
/etc/motd
on your node by editing
recipes/default.rb
to
resemble
Example 7-3
(we'll leave it as an exercise to the reader to modify the copyright
text).
Example 7-3. chefdk/motd/recipes/default.rb
#
# Cookbook Name:: motd
# Recipe:: default
#
# Copyright (C) 2014
#
#
#
cookbook_file
"/etc/motd"
ddo
source
"motd"
mode
"0644"
end
end
Here's an explanation of what each line of code in
Example 7-3
does:
▪
cookbook_file
is a Chef
resource
. The
cookbook_file
resource is used to transfer files
from the
files/
subdirectory in a cookbook to the node.
▪
do
/
end
clauses note that the Chef resource definition spans multiple lines.
▪ The
"/etc/motd"
string passed to
cookbook_file
is the
name
.
name
that defines the
path the file should be copied to on the node.
▪
source
defines the name of the file in the
files/
subdirectory.
▪
mode
defines the octal permissions to set on the file after it is copied. In this case it is
octal 644, “world readable.” If you don't set the file mode appropriately, other users
might not be able to read the contents of this file.
Now that you have created a cookbook directory structure using
chef generate cookbook
,
skip ahead to
Performing Your First Converge
to use Chef to configure your node.