0

我正在开发一个Ganglia食谱Chef。很简单,我构建了四个不同的配置文件,我已经尝试使用 as 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']

基本上它说我没有文件,但我有,在正确的路径上,对吧?

4

1 回答 1

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总有一天,您无论如何都会想添加一些参数。

此外,这是cookbook_fileopscode.com 的文档页面 -

于 2013-05-14T17:50:22.590 回答