Chef cookbook - copy complete directory from files/default location in cookbook to a new location

remote_directory allows you to copy a whole directory to a location of your choice. For example:

remote_directory "/etc/some_target_directory" do
  source 'local_directory' # <-- this is your directory in files/default/local_directory
  files_owner 'root'                                                                 
  files_group 'root'
  files_mode '0750'
  action :create
  recursive true                                                                      
end           

Further reading: https://docs.chef.io/resource_remote_directory.html


There is AFAIK no "good/clean" way to copy all files that are contained in a cookbook.

In order to create multiple files, you can apply simple ruby logic to loop over these files:

['a.txt', 'b.txt'].each do |file|
  cookbook_file "/home/user/work/somelocation/#{file}" do
    source "folder-name/#{file}"
    mode "0644"
  end
end

This will create multiple cookbook_file resources (what @jamesgaddum is talking of).

P.S. the default/ part in files/default/ is optional since couple of Chef versions.

Tags:

Chef Infra