Wednesday, October 19, 2011

Chef template specificity

http://wiki.opscode.com/display/chef/Templates

Template Location Specificity

Cookbooks are often designed to work on a variety of hosts and platforms. Templates often need to differ depending on the platform, host, or function of the node. When the differences are minor, they can be handled with a small amount of logic within the template itself. When templates differ dramatically, you can define multiple templates for the same file. Chef will decide which template to render based on the following rules.
Within a Cookbook's template directory, you might find a directory structure like this:
  • templates
    • host-foo.example.com
    • ubuntu-8.04
    • ubuntu
    • default
For a node with FQDN of foo.example.com and the sudoers.erb resource above, we would match:
  • host-foo.example.com/sudoers.erb
  • ubuntu-8.04/sudoers.erb
  • ubuntu/sudoers.erb
  • default/sudoers.erb
In that order.
Then, for example: sudoers.rb placed under the files/host-foo.example.com/ directory, means it will be only copied to the machine with the domain name foo.example.com. (Note the "host-" prefix to the directory name)
So, the rule distilled:
  1. host-node[:fqdn]
  2. node[:platform]-node[:platform_version]
  3. node[:platform]
  4. default

No comments:

Post a Comment