为什么厨师找不到我的文件?

时间:2013-05-14 14:40:04

标签: linux centos chef knife

我正在Ganglia开发Chef食谱。 非常简单,我构建了四个不同的配置文件,我已经尝试使用template,但为了简单起见,我构建了这些配置文件。

这是我的食谱:

return if tagged?('norun::ganglia')

case node[:platform]
  when "ubuntu", "debian"
    pkg = "ganglia-monitor"
  when "redhat", "centos", "fedora"
    pkg = "ganglia-gmond"
end

package "#{pkg}" do
    action :install
end

cookbook_file "/etc/ganglia/gmond.conf" do
    owner "root"
    group "root"
    mode "0644"
    source "gmond/" + node['base']['dc'] + "/node/gmond.conf" 
end

# Adding ganglia-gmond as service
service "gmond" do
  supports :status => true,
           :restart => true
  action [ :enable, :start ]
end

这就是我的食谱结构:

cookbooks/ganglia/
cookbooks/ganglia/files/default/gmond/* // I have others sub-folders here too
cookbooks/ganglia/files/default/gmond/diveo/node/gmond.conf
cookbooks/ganglia/recipes/default.rb

但是当我尝试运行我的食谱时,它会出现以下错误:

[2013-05-14T14:23:38+00:00] FATAL: Chef::Exceptions::FileNotFound: cookbook_file[/etc/ganglia/gmond.conf] (ganglia::default line 25) had an error: Chef::Exceptions::FileNotFound: Cookbook 'ganglia' (0.1.0) does not contain a file at any of these locations:
  files/centos-5.7/gmond/diveo/node/gmond.conf
  files/centos/gmond/diveo/node/gmond.conf
  files/default/gmond/diveo/node/gmond.conf

This cookbook _does_ contain: ['diveo/monitor/gmond.conf','diveo/node/gmond.conf','awsvir/monitor/gmond.conf','awsvir/node/gmond.conf','awssp/monitor/gmond.conf','awssp/node/gmond.conf','alog/monitor/gmond.conf','alog/node/gmond.conf']

基本上它说我没有文件,但是我做了,在正确的道路上,对吗?

1 个答案:

答案 0 :(得分:3)

如果node['base']['dc']是平台名称,那么cookbook_file语句应该是

cookbook_file "/etc/ganglia/gmond.conf" do
    owner "root"
    group "root"
    mode "0644"
    source "gmond.conf"
end

和conf文件的结构应该是那样的

cookbooks/ganglia/
cookbooks/ganglia/files/default/gmond.conf
cookbooks/ganglia/files/centos-5.7/gmond.conf
...

一点建议 - 使用template代替cookbook_file。有一天,您还需要为gmane.conf添加一些参数。

此外,这是来自opscode.com的cookbook_file doc页面 -