Loop through mult-value node attribute


#1

This should be something simple and not sure what I am missing here.

I have a simple node attribute definition with a multi-value attribute as
default[‘onbio’][‘apps’] = [‘east’,‘west’,‘north’,‘south’]

I am trying to loop through each element of the attributes in my recipe with the code
node[‘onbio’][‘apps’].each do |app|
if #{app} == ‘west’
check_interval_flag = 1
appname = #{app}
end
end

The recipe fails with the error
undefined method `[]’ for nil:NilClass
for the line that starts as
" node[‘onbio’][‘apps’].each do |app|"

Thank you for your comments/thoughts


#2

First of all, you do not need to surround ‘app’ with #{} since it must be a string already.
Second, the error message says it is nil class which means there is nothing assigned at node[‘onbio’][‘apps’].
There must be something wrong on assigning value like If you use policyfile with attributes in it and then run kitchen test, you have to ‘chef update’ whenever you change the attributes.