# Node attribute initialized with empty array reset to nil in recipe in Chef 11

**URL:** <https://discourse.chef.io/t/node-attribute-initialized-with-empty-array-reset-to-nil-in-recipe-in-chef-11/3640>\
**Category:** Chef Infra (archive)\
**Created:** [February 18, 2013, 9:20pm UTC](https://discourse.chef.io/t/node-attribute-initialized-with-empty-array-reset-to-nil-in-recipe-in-chef-11/3640 "2013-02-18T21:20:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bryan\_Berry](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/bryan_berry/32/213_2.png) [@Bryan\_Berry](https://discourse.chef.io/u/Bryan_Berry)\
**Post date:** [February 18, 2013, 9:20pm UTC](https://discourse.chef.io/t/node-attribute-initialized-with-empty-array-reset-to-nil-in-recipe-in-chef-11/3640/1 "2013-02-18T21:20:13Z")

</div>

Dear Chefs,

I am having some pain w/ the Chef 11 migration. The following code  
works fine w/ Chef 10.\* but fails on chef 11.\*

> <https://github.com/lusis/chef-logstash/blob/master/attributes/default.rb#L4>

  
default[‘logstash’][‘join\_groups’] = []

> <https://github.com/lusis/chef-logstash/blob/master/recipes/default.rb#L31>

  
node[‘logstash’][‘join\_groups’].each do |grp|  
group grp do  
members node[‘logstash’][‘user’]  
action :modify  
append true  
only\_if "grep -q ‘^#{grp}:’ /etc/group"  
end

Here is the error I get. Apparently it somehow is set to nil . What  
am i doing wrong?

NoMethodError

* * *

undefined method `each’ for nil:NilClass

Cookbook Trace:

* * *

/etc/vagrant-chef/chef-solo-1/cookbooks/logstash/recipes/default.rb:31:in  
`from_file' /etc/vagrant-chef/chef-solo-1/cookbooks/fao-logstash/recipes/server.rb:10:in`from\_file’

## Relevant File Content:

/etc/vagrant-chef/chef-solo-1/cookbooks/logstash/recipes/default.rb:

24: directory node[‘logstash’][‘basedir’] do  
25: action :create  
26: owner "root"  
27: group "root"  
28: mode "0755"  
29: end  
30:  
31\>\> node[‘logstash’][‘join\_groups’].each do |grp|  
32: group grp do  
33: members node[‘logstash’][‘user’]  
34: action :modify  
35: append true

---

<div class="post-metadata">

**Author:** ![AJ\_Christensen](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/aj_christensen/32/525_2.png) [@AJ\_Christensen](https://discourse.chef.io/u/AJ_Christensen)\
**Post date:** [February 18, 2013, 9:24pm UTC](https://discourse.chef.io/t/node-attribute-initialized-with-empty-array-reset-to-nil-in-recipe-in-chef-11/3640/2 "2013-02-18T21:24:17Z")

</div>

I can't reproduce with 11.4.0 and chef-shell

=\> :ucanhaz\_halp  
chef \> attributes\_mode  
chef:attributes \> default['logstash']['join\_groups'] =   
=\>   
chef:attributes \> recipe\_mode  
chef:recipe \> node['logstash']['join\_groups'].each do |grp|  
chef:recipe \> group grp do  
chef:recipe \> members node['logstash']['user']  
chef:recipe ?\> action :modify  
chef:recipe ?\> append true  
chef:recipe ?\> only\_if "grep -q '^#{grp}:' /etc/group"  
chef:recipe ?\> end  
chef:recipe ?\> end  
=\>   
chef:recipe \> node['logstash']['join\_groups']  
=\>   
chef:recipe \> node['logstash']  
=\> {"join\_groups"=\>}  
chef:recipe \> node['logstash'].key? 'join\_groups'  
=\> true

--AJ

On 19 February 2013 10:20, Bryan Berry [bryan.berry@gmail.com](mailto:bryan.berry@gmail.com) wrote:

> Dear Chefs,
> 
> I am having some pain w/ the Chef 11 migration. The following code  
> works fine w/ Chef 10.\* but fails on chef 11.\*
> 
> [chef-logstash/attributes/default.rb at master · lusis/chef-logstash · GitHub](https://github.com/lusis/chef-logstash/blob/master/attributes/default.rb#L4)  
> default['logstash']['join\_groups'] =
> 
> [chef-logstash/recipes/default.rb at master · lusis/chef-logstash · GitHub](https://github.com/lusis/chef-logstash/blob/master/recipes/default.rb#L31)  
> node['logstash']['join\_groups'].each do |grp|  
> group grp do  
> members node['logstash']['user']  
> action :modify  
> append true  
> only\_if "grep -q '^#{grp}:' /etc/group"  
> end
> 
> Here is the error I get. Apparently it somehow is set to nil . What  
> am i doing wrong?
> 
> NoMethodError
> 
> * * *
> 
> undefined method `each' for nil:NilClass
> 
> Cookbook Trace:
> 
> * * *
> 
> /etc/vagrant-chef/chef-solo-1/cookbooks/logstash/recipes/default.rb:31:in  
> `from_file' /etc/vagrant-chef/chef-solo-1/cookbooks/fao-logstash/recipes/server.rb:10:in `from\_file'
> 
> ## Relevant File Content:
> 
> /etc/vagrant-chef/chef-solo-1/cookbooks/logstash/recipes/default.rb:
> 
> 24: directory node['logstash']['basedir'] do  
> 25: action :create  
> 26: owner "root"  
> 27: group "root"  
> 28: mode "0755"  
> 29: end  
> 30:  
> 31\>\> node['logstash']['join\_groups'].each do |grp|  
> 32: group grp do  
> 33: members node['logstash']['user']  
> 34: action :modify  
> 35: append true

---

<div class="post-metadata">

**Author:** ![luca.carrogu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/luca.carrogu/32/2281_2.png) [@luca.carrogu](https://discourse.chef.io/u/luca.carrogu)\
**Post date:** [June 11, 2018, 9:48am UTC](https://discourse.chef.io/t/node-attribute-initialized-with-empty-array-reset-to-nil-in-recipe-in-chef-11/3640/3 "2018-06-11T09:48:36Z")

</div>

@Bryan_Berry how did you solve this?  
I’m having the same problem switching from 12 to 13+  
From the logs, the attribute/default.rb file is loaded, but the variables are empty when processing the recipes.
