Opscode
Home     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 remote_file resource.

A remote_file resource
A remote_file resource from a URI

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.

If the source is a URI per the second example, Chef will attempt to GET that URI instead.

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 remote_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 remote_file resource, the client will make a SHA-256 checksum of the contents local file. It will ship that, along with the information needed to pick the most specific file. If the checksum matches that of the file on the remote server, we do not transfer the contents.

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

Copyright © 2009 Opscode, Inc. All Rights Reserved.