[chef] RE: If nil how to set attributes


Chronological Thread 
  • From: "Avargil, Raanan" < >
  • To: " " < >
  • Cc: " " < >
  • Subject: [chef] RE: If nil how to set attributes
  • Date: Tue, 16 Sep 2014 04:57:33 +0000
  • Accept-language: en-US

Hi,

Are you sure node[‘kafka’] is well defined?

Maybe the error “undefined method `[]' for nil:NilClass” relates to it.

 

Raanan

 

From: David Montgomery [mailto:
Sent: Tuesday, September 16, 2014 06:09
To:
Subject: [chef] If nil how to set attributes

 

Hi,

Why oh why is this happening?

If nil I need to set an attribute.

node['kafka']['broker_id']

Why do I get the below error?  How do I resolve?

 

Thanks





[192.241.213.141] out:   ================================================================================
[192.241.213.141] out:   Recipe Compile Error in /var/feed-chef/chef-repo/cookbooks/kafka/recipes/default.rb
[192.241.213.141] out:   ================================================================================
[192.241.213.141] out:  
[192.241.213.141] out:   NoMethodError
[192.241.213.141] out:   -------------
[192.241.213.141] out:   undefined method `[]' for nil:NilClass
[192.241.213.141] out:  
[192.241.213.141] out:   Cookbook Trace:
[192.241.213.141] out:   ---------------
[192.241.213.141] out:     /var/feed-chef/chef-repo/cookbooks/kafka/recipes/default.rb:88:in `from_file'
[192.241.213.141] out:  
[192.241.213.141] out:   Relevant File Content:
[192.241.213.141] out:   ----------------------
[192.241.213.141] out:   /var/feed-chef/chef-repo/cookbooks/kafka/recipes/default.rb:
[192.241.213.141] out:  
[192.241.213.141] out:    81:  PYCODE
[192.241.213.141] out:    82:  end
[192.241.213.141] out:    83:    if File.exists?("#{Chef::Config[:file_cache_path]}/zookeeper_hosts")
[192.241.213.141] out:    84:      zookeeper_hosts = File.read("#{Chef::Config[:file_cache_path]}/zookeeper_hosts")
[192.241.213.141] out:    85:    end
[192.241.213.141] out:    86:   
[192.241.213.141] out:    87:     
[192.241.213.141] out:    88>>   if node['kafka']['broker_id'].nil?
[192.241.213.141] out:    89:      node.set['kafka']['broker_id'] = Time.now.getutc.to_i
[192.241.213.141] out:    90:    end
[192.241.213.141] out:    91:    broker_id = node['kafka']['broker_id']
[192.241.213.141] out:    92:    template "/var/kafka/config/server.properties" do
[192.241.213.141] out:    93:      path "/var/config/server.properties"
[192.241.213.141] out:    94:      source "server.properties.local.erb"
[192.241.213.141] out:    95:      owner "root"
[192.241.213.141] out:    96:      group "root"
[192.241.213.141] out:    97:      mode "0644"
[192.241.213.141] out:  
[192.241.213.141] out:  

---------------------------------------------------------------------
Intel Israel (74) Limited

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.




Archive powered by MHonArc 2.6.16.

§