- From: "
" <
>
- To:
- Subject: [chef] RE: If nil how to set attributes
- Date: Mon, 15 Sep 2014 23:32:49 -0400
If you don't actually need to save node['kafka']['broker_id'] back to the Chef server, you could probably also get away with:
broker_id = node['kafka']['broker_id'] || Time.now.getutc.to_i
-Ameir
From:
<
>
To: <
>
Sent: Monday, September 15, 2014
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:
Archive powered by MHonArc 2.6.16.