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

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.*


default[‘logstash’][‘join_groups’] = []


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:infrom_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

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 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
default['logstash']['join_groups'] =

chef-logstash/recipes/default.rb at master · lusis/chef-logstash · GitHub
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

@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.