我正在尝试使用这个github食谱来安装kibana。当我尝试使用以下命令运行它时,我会得到这个错误,在这一点上对我来说没有多大意义。错误指的是什么名称?根据他们的文档,我所要做的就是运行kibana::default
,这本应该完成
chef-client -o 'recipe[kibana::default]'
Starting Chef Client, version 12.15.19
resolving cookbooks for run list: ["kibana::default"]
Synchronizing Cookbooks:
- kibana (0.2.1)
- build-essential (2.3.1)
- ark (2.2.1)
- apt (2.8.0)
Installing Cookbook Gems:
Compiling Cookbooks...
================================================================================
Recipe Compile Error in /var/chef/cache/cookbooks/kibana/recipes/default.rb
================================================================================
ArgumentError
-------------
You must supply a name when declaring a template resource
Cookbook Trace:
---------------
/var/chef/cache/cookbooks/kibana/recipes/_service.rb:3:in `from_file'
/var/chef/cache/cookbooks/kibana/recipes/kibana5.rb:35:in `from_file'
/var/chef/cache/cookbooks/kibana/recipes/default.rb:27:in `from_file'
Relevant File Content:
----------------------
/var/chef/cache/cookbooks/kibana/recipes/_service.rb:
1: # Encoding: utf-8
2:
3>> template node['kibana']['service']['template_file'] do
4: cookbook node['kibana']['service']['cookbook']
5: source node['kibana']['service']['source']
6: mode '0o0755'
7: variables(
8: version: node['kibana']['version'],
9: bin_path: node['kibana']['service']['bin_path'],
10: options: node['kibana']['service']['options'],
11: recent_upstart: (node['platform_family'] != 'rhel')
12: )
Platform:
---------
x86_64-linux
Running handlers:
Running handlers complete
Chef Client failed. 0 resources updated in 03 seconds
在chef中,当您定义资源时,您必须给它一个可以被引用的名称
在本例中:
template 'my_template' do
source 'my_template.erb'
path '/etc/my_template'
end
我正在创建一个模板,并将其命名为"my_template"。通常情况下,该名称将被视为资源的主要组件,在这种情况下,它是path
,因此通常会将目标文件用作等模板的名称
template '/etc/myapp.conf' do
source 'myapp.conf.erb'
end
在这种情况下,name
和path
都是'/etc/myapp.conf'
查看您所引用的烹饪书中的属性文件,node['kibana']['service']['template_file']
属性没有默认值,填充它的case语句以及基于运行时检测到的平台和版本的其他信息。
因此,如果您在它不支持的平台上运行,则该值最终为空(ruby中的nil
),这对于资源上的名称来说是不可接受的值
写入时github中属性文件的相关部分:
# kibana service configurations - defaults to settings for Ubuntu 14.04
case node['platform']
when 'centos', 'amazon'
if node['platform_version'] < '6.9'
default['kibana']['service']['provider'] = Chef::Provider::Service::Init::Redhat
default['kibana']['service']['source'] = 'initd.kibana.erb'
default['kibana']['service']['template_file'] = '/etc/init.d/kibana'
else
default['kibana']['service']['provider'] = Chef::Provider::Service::Systemd
default['kibana']['service']['source'] = 'systemd.service.erb'
default['kibana']['service']['template_file'] = '/usr/lib/systemd/system/kibana.service'
end
when 'ubuntu'
if node['platform_version'] < '16.04'
default['kibana']['service']['provider'] = Chef::Provider::Service::Upstart
default['kibana']['service']['source'] = 'upstart.conf.erb'
default['kibana']['service']['template_file'] = '/etc/init/kibana.conf'
default['kibana']['service']['upstart'] = true
else
default['kibana']['service']['provider'] = Chef::Provider::Service::Systemd
default['kibana']['service']['source'] = 'systemd.service.erb'
default['kibana']['service']['template_file'] = '/lib/systemd/system/kibana.service'
end
end
它不是在那个case块之前建立的,并且case块没有其他语句,所以除了这两种情况(centos、aws或ubuntu)之外,它不会起作用