Information Technology Reference
In-Depth Information
Even though the resources were dynamically created using Ruby interpolation and looping,
they are still available as individual items in the resource list, because of Chef's multiphase
execution.
Similarly, top-level Ruby code is computed during the first phase of execution. When dy-
namically calculating a value (such as the total free memory on a target node), those values
are cached and stored during the first phase of execution:
free_memory = node [ 'memory' ][ 'total' ]
file '/tmp/free' ddo
contents " #{ free_memory } bytes free on #{ Time . now } "
end
end
In the second phase of evaluation, the resource contained in the resource list will be:
file '/tmp/free' ddo
contents "12904899202 bytes free on 2013-07-24 17:47:01 -0400"
end
end
So far, you have seen the file resource, template resource, service resource, and package
resource. These are all resources packaged into the core of Chef. You can find a complete
listing of all resources on the resources page . Here are some of the most commonly used
Chef resources, followed by examples of their basic usage:
bash
Execute multi-line scripts written in the Bourne-again shell (bash) scripting language us-
ing the bash shell interpreter:
# Output 'hello' to the console
bash 'echo "hello"'
chef_gem
Install a gem inside of Chef, for use inside Chef; useful when a Chef code requires a gem
to perform a function:
Search WWH ::




Custom Search