0

我尝试使用chef_handler食谱在厨师中报告,reportchef 当我尝试将其上传到服务器时:

require 'net/http'
require 'uri'

class ReportChef < Chef::Handler
def initialize(opts = nil)
@opts = opts
unless opts[:api_key]
  Chef::Application.fatal!("No ReportChef API Key set")
end
end

def report
params = @opts.merge({ node_name: run_status.node.fqdn })

if run_status.failed?
  params[:last_run_successful] = false
  params[:exception] = run_status.formatted_exception
  params[:backtrace] = run_status.backtrace.join("\n")
else
  params[:last_run_successful] = true
end

uri = URI.parse("http://reportchef.com/api/v1/reports")
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Post.new(uri.request_uri)
request.set_form_data(params)
response = http.request(request)
end
end

错误

knife cookbook upload reportchef -c /etc/chef/knife.rb
Uploading reportchef     [1.0.1]
FATAL: Cookbook file files/default/reportchef.rb has a ruby syntax error:
FATAL: /software/chef-repo/cookbooks/reportchef/files/default/reportchef.rb:13: syntax    
error
FATAL:     params = @opts.merge({ node_name: run_status.node.fqdn })
FATAL:                                      ^
FATAL: /software/chef-repo/cookbooks/reportchef/files/default/reportchef.rb:13:     syntax   
error
FATAL:     params = @opts.merge({ node_name: run_status.node.fqdn })
FATAL: 

发生了什么?

它是下载的代码。

4

1 回答 1

0

您可能在您的服务器上使用 Ruby 1.8,而在 1.8 中缺少一些特定的语法糖,允许您在 1.9 中编写{a: 'b'}(相当于{:a => 'b'})。

您应该尝试在您的服务器上安装 Ruby 1.9 或鼓励作者创建向后兼容性(不推荐,因为恕我直言不支持 1.8)。

于 2013-03-14T18:09:19.127 回答