Information Technology Reference
In-Depth Information
Add an attribute specifying the download URL for the Chef Server package that you ob-
tained from http://www.getchef.com/chef/install . We recommend using the 11.1.4 version
URL shown in Example A-2 , as we wrote the examples for this chapter using this version.
Example A-2. /chefdk/chef-repo/cookbooks/chef-server/attributes/default.rb
default [ ' chef - server ' ][ ' url ' ] = \
' https : //o pscode - omnibus - packages . s3 . amazonaws . com / el / 6 / x86_64 ' \
' / chef - server - 11 . 1 . 4 - 1 . el6 . x86_64 . rpm '
Let's take an initial stab at coding a recipe to replicate the manual steps required to install
Chef Server outlined in How to Install Open Source Chef Server Manually . Enter in the first
version of the code as shown in Example A-3 . Let's go over some of the highlights of the
code in the following paragraphs.
Rather than typing in long variable names such as node['chef-server']['url'] , feel free
to use temporary local variables in a recipe with shorter names, such as:
package_url = node [ 'chef-server' ][ 'url' ]
Remember that you have the full power of Ruby classes and methods available to you in
your Chef recipes, so don't be afraid to use it. For example, you can use the
::File.basename() method to extract the package name from the URL. The package name
is the last component of the URL after the forward slash (“/”): chef-serv-
er-11.1.4-1.el6.x86_64.rpm . Refer to the Ruby core API documentation for more in-
formation on the ::File class:
package_name = :: File . basename ( package_url )
Unfortunately, the package resource does not work with URLs, so we're introducing a new
resource, the remote_file resource. The remote_file resource will download files from a
remote location. Rather than hardcoding a path like “/tmp” for the package download, Chef
provides a variable you should use instead: Chef::Config[:file_cache_path] . Let Chef
choose the best place to store temporary files for you. Pass the local path where you want to
store the file as a string parameter to remote_file or as a name attribute; in this case, we use
the package_local_path variable. The download URL should be passed to remote_file as
the source attribute.
The package resource should be familiar to you by now—we used it in Chapter 7 .
Search WWH ::




Custom Search