2015-05-11 72 views
0

我試圖做一個廚師跑,但不斷收到標題中的錯誤。日誌輸出如下;在資源模板[/etc/awslogs//cwlogs.cfg]上執行操作'創建`''

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

如何定義'node ['cloudwatch-cookbook'] ['cwlogs'] ['logfiles']'屬性?你可以發表一些例子嗎?看起來你正在訪問它們作爲節點['cloudwatch-cookbook'] ['cwlogs'] ['logfiles']是一個hashmap,但它是一個數組。 –

+0

日誌文件是這樣定義的; \t \t' '的日誌文件'=> '@ CW_LOG_FILE @', \t \t '組名'=> '@ CW_GROUP_NAME @', \t \t 'streamName中'=> '{INSTANCE_ID}''和屬性通過一個JSON傳遞文件名爲「cloudwatch-cookbook」:{ 「cwlogs」:{ 「logfiles」:{ 「logfile」:「/ var/log/syslog」, 「groupname」:「Project」, 「streamname」 「Project」 }, 「region」:「eu-west-1」 } }' –

回答

1

問題是.each已經返回|key, value|。你只是抓住了key這是一個字符串。然後,您打電話string['something']哪些預計索引字符串。

如果更改行29閱讀:

<% node['cloudwatch-cookbook']['cwlogs']['logfiles'].values do |group| -%> 

你要善於去。

+0

很好用。謝謝! –

相關問題