Opscode
Home     Introduction to Chef     Cookbooks     Blog     GitHub     Tickets 

Files

Often, you need to distribute files to your servers. The Files within a cookbook are where you can do just that. They are reached via the cookbook_file resource.

A cookbook_file resource

The above resource would create /usr/local/bin/apache2_module_conf_generate.pl from the apache2_module_conf_generate.pl file contained in the cookbook that was most specific to the Node executing the recipe. By default, it looks for File Specificity from the remote_url setting in the Client configuration.

File Specificity

Often, Cookbooks will work on multiple platforms, or distribute files that are only subtly different depending on the platform. Chef Cookbooks allow you to only specify those files one time, but make sure that the right file ends up on each system. Within a Cookbook's files or templates directories, you might find a directory structure like this:

  • files/ (or templates/)
    • host-foo.example.com
    • ubuntu-8.04
    • ubuntu
    • default

Given this resource:

A cookbook_file resource

We would match:

  • host-foo.example.com/apache2_module_conf_generate.pl
  • ubuntu-8.04/apache2_module_conf_generate.pl
  • ubuntu/apache2_module_conf_generate.pl
  • default/apache2_module_conf_generate.pl

In that order (given a Node named foo.example.com running Ubuntu 8.04). Then for example, if we put apache_module_conf_generate.pl under files/host-foo.example.com/ directory it will be only copied to the machine with the domain name foo.example.com.

So, the rule distilled:

  1. host-node[:fqdn]
  2. node[:platform]-node[:version]
  3. node[:platform]
  4. default
Hey, Cfengine people!

This is inspired by Single Copy Nirvana - if you think about it that way, this will click immediately.

When does a file get transferred?

When you run a cookbook_file resource, the client will calculate the checksum of local file. It compares this checksum against the checksum of the most specific available version of the file in the cookbook. If the checksums match, the file will not be transferred. Additionally, cookbook files are loaded lazily from the server--a cookbook may contain many cookbook files, but they are only transferred to the client as they are needed.

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

Copyright © 2009 Opscode, Inc. All Rights Reserved.