Resource for copy local file?


#1

Which chef resource type can I use to copy a local file, for example, copy
local file from /tmp/1.txt to /root/1.txt?

I know in puppet I can do like this:
file{ “/root/1.txt”, ensure => present, source => “/tmp/1.txt”, }

But how can I do this by chef? I looked into file, template, cookbook_file,
remotefile, it looks no resource type can handle it. Could anyone give me some
advice on this?


#2

Hello,

On Sun, Aug 28, 2011 at 7:47 PM, zkfhu@yahoo.com wrote:

Which chef resource type can I use to copy a local file, for example, copy
local file from /tmp/1.txt to /root/1.txt?

I know in puppet I can do like this:
file{ “/root/1.txt”, ensure => present, source => “/tmp/1.txt”, }

But how can I do this by chef? I looked into file, template, cookbook_file,
remotefile, it looks no resource type can handle it. Could anyone give me some
advice on this?

To directly answer the question, you want to use the "content"
parameter of the file resource, using the Ruby IO.read() method.

file “/root/1.txt” do
content IO.read("/tmp/1.txt")
end

However, I ask why are you doing this? Is the source coming from Chef
in the first place? Or is it a “state” file dropped off by some other
process or resource such as an execute or bash script? Better knowing
the use case may lead to a better, more reliable solution.


Opscode, Inc
Joshua Timberman, Director of Training and Services
IRC, Skype, Twitter, Github: jtimberman