How to copy a directory using chef resource ?


I have a requirement to copy a folder from one location to another location in Linux server using chef cookbook resource. Tried below code:

remote_file "Copy service" do
path "/tmp/bakup" source "/vagrant/app"
owner 'root'
group 'root'
mode 0755


Hulk Asked on September 7, 2016 in Tools & Automation.
Add Comment
1 Answer(s)
Best answer

There is no chef resource to copy from the same server. You can use the bash resource and use cp command. You can make the block idempotent use not_if command.

bash 'copy file' do

cwd ::File.dirname(src_filepath)

code <<-EOH

cp -r folder /path/to/destination


not_if { ::File.exists?(/path/to/destination) }


Hope it helps.

Flash Answered on September 9, 2016.

Thanks, Micheal. It helped. I am wondering, why there is no resource for copying a folder ?

on September 15, 2016.
Add Comment

Your Answer

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