How can we use the attribute "path" in cookbook_file?


#1

Good day.
We have a problem. We are trying to copy a file from one
folder to
another, using “cookbook_file” using the attribute “path”.
Example code:

cookbook_file “/opt/server.tgz” do
path “/mnt/server/”

source "server.tgz"
end

But the chef throws an error:

FATAL: Chef::
Exceptions:: FileNotFound: cookbook_file [/opt/
server.tgz]
(copy_file_rep:: default line 9) had an error: cookbook
copy_file_rep
does not contain file files/server.tgz

How can we use the attribute
"path"?

Thank you!


Best Regards,
Ilya


#2

cookbook_file resource is used for retrieval of remote content. This means
the file is downloaded from sever. To copy file on the local system just use
file resource.
On Sep 22, 2011 3:37 PM, “Ilya” ilya@notarikon.net wrote:

Good day.
We have a problem. We are trying to copy a file from one
folder to
another, using “cookbook_file” using the attribute “path”.
Example code:

cookbook_file “/opt/server.tgz” do
path “/mnt/server/”

source "server.tgz"
end

But the chef throws an error:

FATAL: Chef::
Exceptions:: FileNotFound: cookbook_file [/opt/
server.tgz]
(copy_file_rep:: default line 9) had an error: cookbook
copy_file_rep
does not contain file files/server.tgz

How can we use the attribute
"path"?

Thank you!


Best Regards,
Ilya


#3

Hello!

On Thu, Sep 22, 2011 at 4:36 AM, Ilya ilya@notarikon.net wrote:

We have a problem. We are trying to copy a file from one folder to
another, using “cookbook_file” using the attribute “path”. Example code:

cookbook_file “/opt/server.tgz” do
path "/mnt/server/"
source "server.tgz"
end

“path” is the “name parameter attribute” for cookbook_file,
remote_file, template and file resources, as described in the Resource
documentation0. The name is the string following the resource type.
Above, this is “/opt/server.tgz”.

To use the cookbook_file resource, you put the source file in the
’files/default’ directory of the cookbook where the recipe is located
and Chef will retrieve it from the server to put into the path
location when it configures the resource on the node.

cookbook_file “/mnt/server/server.tgz” do
source "server.tgz"
end

Will put it in the /mnt/server location as long as the source is in
the cookbook.

If you want to copy a file’s contents from one location to another,
you can use the file resource with the content parameter that calls
the Ruby IO object’s read method.

file “/mnt/server/server.tgz” do
content IO.read("/opt/server.tgz")
end

The file “/opt/server.tgz” must exist during the compile phase1.


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