NoMethodError - undefined method `[]' for nil:NilClass


#1

I have the below in a chef recipie

server_type = node[:test][:server_type]

In a role I have the below:

default_attributes “test” => { “server_type” => ‘Compute’ }

yet I get the below error

35:
36>> server_type = node[:test][:server_type]
[2013-07-18T01:16:55+00:00] DEBUG: Re-raising exception: NoMethodError -
undefined method `[]’ for nil:NilClass

How do I resolve?


#2

Hi,

This error message happens if there is no node[:test] attribute set.

Does your node have your role in its run list or did you only add the cookbook containing your recipe to it by accident?

Am 18.07.2013 um 03:23 schrieb David Montgomery davidmontgomery@gmail.com:

I have the below in a chef recipie

server_type = node[:test][:server_type]

In a role I have the below:

default_attributes “test” => { “server_type” => ‘Compute’ }

yet I get the below error

35:
36>> server_type = node[:test][:server_type]
[2013-07-18T01:16:55+00:00] DEBUG: Re-raising exception: NoMethodError - undefined method `[]’ for nil:NilClass

How do I resolve?