Pergunta

I have a file present in templates directory of my cookbook, and I am trying to copy that file to a node.

The default.rb of my cookbook is:

remote_file "#{ENV['HOME']}/p.txt" do
  source "file:///home/chef/chef-repo/cookbooks/remote_file/templates/default/p.txt.erb"
  mode "0644"
end

When I am doing a chef-client on the node I am getting following error:

[2014-04-03T18:44:25+05:30] INFO: Loading cookbooks [remote_file]
Synchronizing Cookbooks:
[2014-04-03T18:44:25+05:30] INFO: Storing updated cookbooks/remote_file/recipes/default.rb in the cache.
  - remote_file
Compiling Cookbooks...
Converging 1 resources
Recipe: remote_file::default
  * remote_file[/home/node/p.txt] action create[2014-04-03T18:44:25+05:30] INFO:     Processing remote_file[/home/node/p.txt] action create (remote_file::default line 10)
[2014-04-03T18:44:25+05:30] WARN: remote_file[/home/node/p.txt] cannot be downloaded from file:///home/chef/chef-repo/cookbooks/remote_file/templates/default/p.txt.erb: No such file or directory - /home/chef/chef-repo/cookbooks/remote_file/templates/default/p.txt.erb

================================================================================
Error executing action `create` on resource 'remote_file[/home/node/p.txt]'
================================================================================


Errno::ENOENT
-------------
No such file or directory - /home/chef/chef-    repo/cookbooks/remote_file/templates/default/p.txt.erb

Why I am not able to copy the file on node. What am I doing wrong, Can anyone help me?

Foi útil?

Solução

If you're trying to render a text file from a template (which it looks like you are), then use the template resource instead of remote_file:

template "#{ENV['HOME']}/p.txt" do
  source "p.txt.erb"
  mode "0644"
end

If instead it's just a simple static file that you're trying to get into the node, then the cookbook_file resource would be more appropriate. To use that, move your file to <cookbook>/files/default/p.txt and add the resource:

cookbook_file "#{ENV['HOME']}/p.txt" do
  source "p.txt"
  mode "0644"
end
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top