cookbook_file differs from something like a template is in that cookbook_file is for purely static content. There is no room for variables or dynamic content.
It transfers files from a sub-directory of a cookbook to the node.
Cookbook files are shipped with cookbook itself. These are cookbook files like configuration files, PHP files, things that are unlikely to change.
Example:
Generate a cookbook_file using the command:
chef generate file {{ cookbook }} {{ file_name }}
like below:
chef generate file apache index.html
Use cookbook_file resource:
package 'apache2'
cookbook_file '/var/www/html/index.html' do
source 'index.html'
end
service 'apache2' do
action [:enable, :start ]
end
Fill in cookbook_file index.html in the cookbook:
$ cat apache/files/default/index.html
Hello world!
Converge the cookbook apache:
sudo chef-client -zr 'recipe[apache]'
Test the cookbook:
$ curl localhost
Hello world!