# Undefined method \`\[\]' for nil:NilClass

**URL:** <https://discourse.chef.io/t/undefined-method-for-nil-nilclass/1360>\
**Category:** Chef Infra (archive)\
**Created:** [February 18, 2010, 8:37am UTC](https://discourse.chef.io/t/undefined-method-for-nil-nilclass/1360 "2010-02-18T08:37:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Oliver\_Rojo](https://avatars.discourse-cdn.com/v4/letter/o/c6cbf5/32.png) [@Oliver\_Rojo](https://discourse.chef.io/u/Oliver_Rojo)\
**Post date:** [February 18, 2010, 8:37am UTC](https://discourse.chef.io/t/undefined-method-for-nil-nilclass/1360/1 "2010-02-18T08:37:25Z")

</div>

How can i fix this error?

Chef::Mixin::Template::TemplateError (undefined method `[]’ for nil:NilClass)

I’m using:

\<%= @localhost[“ipaddress”] %\> on one of my template and suddenly after running chef-client, it stops with the above error.

Please help!

Oliver

---

<div class="post-metadata">

**Author:** ![Alex\_Soto](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/alex_soto/32/673_2.png) [@Alex\_Soto](https://discourse.chef.io/u/Alex_Soto)\
**Post date:** [February 18, 2010, 8:45am UTC](https://discourse.chef.io/t/undefined-method-for-nil-nilclass/1360/2 "2010-02-18T08:45:31Z")

</div>

@node is how to get node attributes unless you defined a variable named localhost.

On Feb 18, 2010, at 12:37 AM, Oliver Rojo wrote:

> How can i fix this error?
> 
> Chef::Mixin::Template::TemplateError (undefined method `' for nil:NilClass)
> 
> I'm using:
> 
> \<%= @localhost["ipaddress"] %\> on one of my template and suddenly after running chef-client, it stops with the above error.
> 
> Please help!
> 
> Oliver
