2013-03-04 52 views
0

我試圖通過capistrano出於某種原因部署,我越來越:無法將「散」到「字符串」

/Users/mysite/.rvm/gems/[email protected]/gems/json-1.4.6/lib/json/common.rb:146:in `initialize': can't convert Hash into String (TypeError) 
    from /Users/mysite/.rvm/gems/[email protected]/gems/json-1.4.6/lib/json/common.rb:146:in `new' 
    from /Users/mysite/.rvm/gems/[email protected]/gems/json-1.4.6/lib/json/common.rb:146:in `parse' 
    from /Users/mysite/.rvm/gems/[email protected]/gems/chef-capistrano-0.1.0/lib/chef/capistrano.rb:27:in `role_from_chef' 
    from ./config/deploy.rb:35:in `block in load' 

中的問題的線條我config/deploy.rb是:

after 'multistage:ensure' do 
role_from_chef :db, 'app', :limit => 1, :primary => true # perform db operations on one of the app servers 
role_from_chef :web, 'app' 
role_from_chef :app 
role_from_chef :queue 
role_from_chef :cron 
end 

第二行是行35

更新的代碼

def role_from_chef(cap_role, *roles) 
    %w(chef_host chef_port chef_scheme chef_client_name chef_key_file).each do |value| 
     abort "Please set :#{value}" unless exists?(value.to_sym) 
    end 

    Spice.setup do |s| 
     s.host = fetch(:chef_host) 
     s.port = fetch(:chef_port) 
     s.scheme = fetch(:chef_scheme) 
     s.client_name = fetch(:chef_client_name) 
     s.key_file = fetch(:chef_key_file) 
    end 
    Spice.connect! 

    options = roles.extract_options! 
    roles = [cap_role.to_s] if roles.empty? 
    search_roles = fetch(:chef_search_roles) + roles 
    query = search_roles.map{|r| "role:#{r}"}.join(" AND ") 

    response = Spice.connection.get("/search/node?q=#{URI.encode(query)}")   
    response_object = JSON.parse(response) 
    raise response_object['error'].join(' ') if response_object.has_key?('error') 

    nodes = response_object['rows'] 
    hosts = nodes.select{|n| n['ec2']}.map{|n| n['ec2']['public_hostname']} 

    if limit = options.delete(:limit) 
     hosts = hosts.slice(0, limit) 
    end 

    hosts.each do |host| 
     node = nodes.detect { |n| n['ec2']['public_hostname'] == host } 
     puts "#{cap_role}: #{node['ec2']['instance_id']} - #{node['ec2']['public_hostname']}" 
    end 

    hosts << options 
    role cap_role, *hosts 
    end 

回答

1
role_from_chef :db, 'app', :limit => 1, :primary => true 

相當於

role_from_chef(:db, 'app', { :limit => 1, :primary => true }) 

按照錯誤,我要說的是,你的功能role_from_chef不接受String作爲第三個參數。但是,如果沒有粘貼role_from_chef函數,我無法確定。

總之這是你應調查什麼:按照第三個參數裏面role_from_chef,看看它作爲一個字符串某處

+0

我更新的'role_from_chef'做什麼碼 – Shamoon 2013-03-05 16:35:53