无法在chef-client(节点)上复制文件

时间:2014-04-03 13:24:32

标签: chef chef-recipe chef-solo

我的cookbook的templates目录中有一个文件,我正在尝试将该文件复制到节点。

我的食谱的 default.rb 是:

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

当我在节点上做一个厨师客户端时,我收到以下错误:

[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

为什么我无法在节点上复制文件。我做错了什么,任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:3)

如果您尝试从模板中渲染文本文件(看起来像是这样),请使用template资源而不是remote_file

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

如果它只是一个您尝试进入节点的简单静态文件,那么cookbook_file资源会更合适。要使用它,请将文件移至<cookbook>/files/default/p.txt并添加资源:

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