我正在尝试做一名厨师,但仍然在标题中收到错误。日志输出如下;
Project: Error executing action `create` on resource 'template[/etc/awslogs//cwlogs.cfg]'
Project: ================================================================================
Project:
Project: Chef::Mixin::Template::TemplateError
Project: ------------------------------------
Project: no implicit conversion of String into Integer
Project:
Project: Resource Declaration:
Project: ---------------------
Project: # In /tmp/packer-chef-solo/cookbooks-0/cloudwatch-cookbook/recipes/logconfig.rb
Project:
Project: 21: template "#{node['cloudwatch-cookbook']['cwlogs']['directory']}/#{node['cloudwatch-cookbook']['cwlogs']['configfilename']}" do
Project: 22: source "cwlogs.cfg.erb"
Project: 23: owner "root"
Project: 24: group "root"
Project: 25: mode 0644
Project: 26: variables(
Project: 27: :cookbook_name => "cloudwatch-cookbook"
Project: 28: )
Project: 29: end
Project:
Project: Compiled Resource:
Project: ------------------
Project: # Declared in /tmp/packer-chef-solo/cookbooks-0/cloudwatch-cookbook/recipes/logconfig.rb:21:in `from_file'
Project:
Project: template("/etc/awslogs//cwlogs.cfg") do
Project: action "create"
Project: retries 0
Project: retry_delay 2
Project: default_guard_interpreter :default
Project: path "/etc/awslogs//cwlogs.cfg"
Project: backup 5
Project: atomic_update true
Project: source "cwlogs.cfg.erb"
Project: variables {:cookbook_name=>"cloudwatch-cookbook"}
Project: declared_type :template
Project: cookbook_name :"cloudwatch-cookbook"
Project: recipe_name "logconfig"
Project: mode 420
Project: owner "root"
Project: group "root"
Project: end
Project:
Project: Template Context:
Project: -----------------
Project: on line #31
Project: 29: <% node['cloudwatch-cookbook']['cwlogs']['logfiles'].each do |group| -%>
Project: 30:
Project: 31: [<%= group['groupname'] %>_<%= group['logfile'] %>]
Project: 32: datetime_format = [%Y-%m-%d %H:%M:%S]
Project: 33: log_group_name = <%= group['groupname'].gsub(' ', '_') %>
Project:
Project: Recipe: apache2::default
Project: * service[apache2] action reload
Project: - reload service service[apache2]
Project:
Project: Running handlers:
Project: [2015-05-11T11:03:15+00:00] ERROR: Running exception handlers
Project: Running handlers complete
Project: [2015-05-11T11:03:15+00:00] ERROR: Exception handlers complete
Project: [2015-05-11T11:03:15+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
Project: Chef Client failed. 99 resources updated in 301.919689764 seconds
Project: [2015-05-11T11:03:15+00:00] ERROR:
Project:
Project: Chef::Mixin::Template::TemplateError (no implicit conversion of String into Integer) on line #31:
Project:
Project: 29: <% node['cloudwatch-cookbook']['cwlogs']['logfiles'].each do |group| -%>
Project: 30:
Project: 31: [<%= group['groupname'] %>_<%= group['logfile'] %>]
Project: 32: datetime_format = [%Y-%m-%d %H:%M:%S]
Project: 33: log_group_name = <%= group['groupname'].gsub(' ', '_') %>
Project:
Project: (erubis):31:in `[]'
Project: (erubis):31:in `block (2 levels) in evaluate'
Project: (erubis):29:in `each'
Project: (erubis):29:in `block in evaluate'
我已经尝试查看类似问题的现有答案,但他们都发现了不同的问题,这些问题似乎并不能反映出我的情况。
有人有任何建议吗?
答案 0 :(得分:1)
问题是a上的.each
将返回|key, value|
。你只抓取key
这是一个字符串。然后调用string['something']
,它需要字符串索引。
如果您将第29行更改为:
<% node['cloudwatch-cookbook']['cwlogs']['logfiles'].values do |group| -%>
你应该好好去。