Undefined method `match' for nil:NilClass

I’m a bit new to Chef server and I’m trying to figure out why this is happening only on Suse 12…same cookbooks work on RHEL 6.

Basically, I’ve got a cookbook that gets the following error when I run it:


undefined method `match’ for nil:NilClass
Did you mean? catch

Cookbook Trace:

/var/chef/cache/cookbooks/test/attributes/logs.rb:5:in `from_file’

Relevant File Content:


1: override[‘logs’][‘region’] = 'us-west-2’
3: default[‘logs’][‘logfiles’][‘systemavailablelog’] = {
4: :log_stream_name => “#{node[‘hostname’]}-available.log”,
5>> :log_group_name => node[‘hostname’].match(/[a-zA-Z]*/),
6: :file => “#{node[‘test’][‘appdir’]}/#{node[‘test’][‘sid’]}/#{node[‘test’][‘sid’]}#{node[‘test’][‘instance’]}/#{node[‘hostname’]}/trace/available.log”,
7: :initial_position => 'end_of_file’
8: }

I’m not sure why it doesn’t like the ‘match’ in line 5. Haven’t been able to find any information about this anywhere yet.

Anyone have any ideas?

This means node['hostname'] is nil, which means either your hosts file or DNS are broken and need to be fixed. You can check by running hostname and/or hostname -f (node['fqdn']) from a command line.


Thanks for the reply!

Running ‘hostname’ returns the host name of the system. It did not like the second command. Not sure if there’s just something weird about how SuSE handles that command? Again, I’m new to this stuff.


I think I found it…

I just noticed that the other references to hostname were in the format:


The problem one is in the format:

Can’t believe I didn’t catch that.

That is only working because nil.to_s == '', not because you actually have a hostname set. You need to fix that actual problem.

@dcarrington I'm facing the same issue, may i know how you fixed it.

@naren this thread is 3 years old, you may want to open up a new one instead to avoid people confusing context (I was about to :open_mouth: ). `undefined method somemethod for nil:NilClass could be a lot of things, but the most common suspect is bad interpolation; You have a variable that is not interpolating at all, or is getting assigned a nil value somehow.

Take a moment to open up a thread with more details on your issue (specifically, we'll need to see code). I'll pop my head in there later today and have a look myself if you want.

okay thanks!