Reputation: 23
The error occurs while trying to converge node.
NoMethodError
-------------
undefined method `[]' for nil:NilClass
Cookbook Trace:
---------------
/tmp/kitchen/cache/cookbooks/system/recipes/filebeat.rb:30:in `block in from_file'
/tmp/kitchen/cache/cookbooks/system/recipes/filebeat.rb:24:in `from_file'
/tmp/kitchen/cache/cookbooks/system/recipes/default.rb:88:in `from_file'
/tmp/kitchen/cache/cookbooks/role-base/recipes/default.rb:1:in `from_file'
Relevant File Content:
----------------------
/tmp/kitchen/cache/cookbooks/system/recipes/filebeat.rb:
23: # Lay down newrelic-infra agent config
24: template '/etc/filebeat/filebeat.yml' do
25: source 'filebeat/filebeat.yml.erb'
26: owner 'root'
27: group 'root'
28: mode '00600'
29: variables(
30>> 'cloud_id' => elastic_credentials[node.chef_environment]['cloud_id'],
31: 'cloud_auth' => elastic_credentials[node.chef_environment]['cloud_auth']
32: )
33: notifies :restart, 'service[filebeat]', :delayed
34: end
Provisioner settings:
provisioner:
product_name: chef
environments_path: ./test/integration/environments/
data_bags_path: ./test/integration/data_bags/
product_version: 13
JSON data_bag file:
{
"id": "elastic",
"production" : {
"cloud_id": "test",
"cloud_auth": "test"
}
}
Issue isn't reproduced if kitchen uses chef_zero, however I need chef version versatility, so problem is relevant.
Upvotes: 0
Views: 75
Reputation: 21226
Your node.chef_environment
is obviously something other than "production". Therefore elastic_credentials[node.chef_environment]
returns nil
, and you cannot call []
on nil
.
If you need to debug the values of the variables, like elastic_credentials
. You can login into your node, find the chef cache folder for the cookbooks (often /etc/chef/cache/cookbooks/
) and add some pp elastic_credentials
here and there.
After that run chef-client --skip-cookbook-sync
and chef will run without downloading cookbooks from Chef Server, but solely on cache and you will see your values printed in console.
Upvotes: 0