我正在尝试使用this github cookbook来安装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
答案 0 :(得分:1)
在定义资源时,在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'
查看您正在引用的cookbook中的属性文件,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块没有else语句,所以在这两种情况之外(centos,aws或ubuntu)它不会起作用