# Loop through mult-value node attribute

**URL:** <https://discourse.chef.io/t/loop-through-mult-value-node-attribute/13271>\
**Category:** Chef Infra (archive)\
**Created:** [July 8, 2018, 6:26am UTC](https://discourse.chef.io/t/loop-through-mult-value-node-attribute/13271 "2018-07-08T06:26:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Riker](https://avatars.discourse-cdn.com/v4/letter/j/90db22/32.png) [@John\_Riker](https://discourse.chef.io/u/John_Riker)\
**Post date:** [July 8, 2018, 6:26am UTC](https://discourse.chef.io/t/loop-through-mult-value-node-attribute/13271/1 "2018-07-08T06:26:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Don](https://avatars.discourse-cdn.com/v4/letter/d/ed655f/32.png) [@Don](https://discourse.chef.io/u/Don)\
**Post date:** [July 9, 2018, 2:15am UTC](https://discourse.chef.io/t/loop-through-mult-value-node-attribute/13271/2 "2018-07-09T02:15:32Z")

</div>

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.
