I am a beginner to Chef. Can any one please advise if there is a way to copy a directory inside cookbook's files/default
directory to a different location.
E.g. I have a directory structure with files a.txt
and b.txt
in files/
directory as follows cookbook_name/files/default/folder-name/[a.txt,b.txt]
. I want them both files to be a location /home/user/work/somelocation/folder-name/[a.txt,b.txt]
I have tried cookbook_file resource as follows:
cookbook_file '/home/user/work/somelocation/' do
source ['folder-name']
mode "0644"
action :create
end
and
cookbook_file '/home/user/work/somelocation/' do
source ['folder-name/a.txt',''folder-name/b.txt'']
mode "0644"
action :create
end
I am aware of other means of copying files between arbitrary directories by looping through, but I am keen to know if there is more elegant way to handle directories akin to how cookbook_file handles files from standard folders inside cookbook's files/default
directory.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With