Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a directory structure (sample data) that I want to copy from within a Chef recipe. It seems the only way to do this is to explicitly create each individual directory and file:

directory "/mnt/data/experiment1/dataset1" do
   recursive true
   only_if { node.chef_environment == "dev" }
end


directory "/mnt/data/experiment1/dataset2" do
   recursive true
   only_if { node.chef_environment == "dev" }
end

directory "/mnt/data/experiment2/dataset1" do
   recursive true
   only_if { node.chef_environment == "dev" }
end


directory "/mnt/data/experiment1/dataset2" do
   recursive true
   only_if { node.chef_environment == "dev" }
end


cookbook_file "/mnt/data/experiment1/dataset1/testfile1.txt" do
   owner "atom"
   group "atom"
   mode "0644"
   source "sampledata/experiment1/dataset1/testfile1.txt"
   only_if { node.chef_environment == "dev"}
end

...

Is there a way to simply recursively copy an entire directory structure from the cookbook? Specifying the name of each file inside the recipe seems redundant and error-prone (ie, if we add a file to the tree but forget to reference it in the recipe, it won't be copied.)

I guess a hack workaround would be to work out where all the chef files get copied to on the target machine and do a cp -r but is there something cleaner?

Or am I going about this the wrong way?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

Why not using remote_directory resource. It's intended exactly for that.

See: http://docs.opscode.com/resource_remote_directory.html

share|improve this answer
1  
That looks right - is it new by any chance? Also it seems that remote_file and remote_directory behave completely differently (let alone cookbook_file and file). What a confusing mess... –  Steve Bennett Jan 8 '13 at 3:22
1  
It is confusing. There are a lot of discussions about that. Anyway - you should check Puppet. That's synonym for "messy" :) –  Michael Field Jan 8 '13 at 13:36

file_cache_path will tell you where the cookbooks are located on the target machine

Therefore you just need to sync your cookbook's directory within file_cache_path to your target location. You could do that with a cp -r, a ruby_block using FileUtils#cp_r, or some other cleverness I haven't thought of.

share|improve this answer
    
Hmm. Well, it turns out that directories under files/default aren't copied to the target machine anyway. Maybe the simplest way would be to provide all the files in a zip, copy that, then unzip it. –  Steve Bennett Sep 18 '12 at 3:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.