Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined method `[]' for nil:NilClass #419

Closed
agit05 opened this issue Jul 4, 2016 · 7 comments
Closed

undefined method `[]' for nil:NilClass #419

agit05 opened this issue Jul 4, 2016 · 7 comments

Comments

@agit05
Copy link

agit05 commented Jul 4, 2016

I have the following issue while trying to install wordpress cookbook which is calling the nginx one:

Recipe Compile Error in /var/chef/cache/cookbooks/wordpress/recipes/nginx.rb

NoMethodError

undefined method `[]' for nil:NilClass

Cookbook Trace:

/var/chef/cache/cookbooks/nginx/recipes/ohai_plugin.rb:27:in from_file' /var/chef/cache/cookbooks/nginx/recipes/package.rb:21:infrom_file'
/var/chef/cache/cookbooks/nginx/recipes/default.rb:22:in from_file' /var/chef/cache/cookbooks/wordpress/recipes/nginx.rb:43:infrom_file'

Relevant File Content:

/var/chef/cache/cookbooks/nginx/recipes/ohai_plugin.rb:

20: #
21:
22: ohai 'reload_nginx' do
23: plugin 'nginx'
24: action :nothing
25: end
26:
27>> template "#{node['ohai']['plugin_path']}/nginx.rb" do
28: source 'plugins/nginx.rb.erb'
29: owner 'root'
30: group node['root_group']
31: mode '0755'
32: notifies :reload, 'ohai[reload_nginx]', :immediately
33: end
34:
35: include_recipe 'ohai::default'

Chef settings on the Workstation (where the cookbook is installed):
chef-client -v
Chef: 11.16.2
knife cookbook show wordpress
wordpress 3.0.0
knife cookbook show nginx
nginx 2.7.6
knife cookbook show ohai
ohai 4.1.1

Chef settings on the client (target) server:
chef-client -v
Chef: 12.5.1

chef-client -o wordpress works fine, installs Apache and Wordpress at the end, but I want to install Nginx version.
Any clue about this error ?
Thanks.

@wvega
Copy link

wvega commented Jul 5, 2016

This issue seems to be caused by a breaking change in Ohai 4.0.0. See: priestjim/chef-openresty#47.

They solved the problem by using the new ohai_plugin resource, instead of manually creating the plugin file in the Ohai's plugins directory.

As mentioned in the linked issue, forcing Berkshelf to use Ohai older than 4.0.0 solved the issue for me.

Add the following to your Berksfile:

cookbook 'ohai', '< 4.0.0'

and then run

berks update ohai

You may need to change the versions of other cookbooks as well, if any of them depends on Ohai > 4.0.0 and is causing a conflict for Berkshelf.

@agit05
Copy link
Author

agit05 commented Jul 5, 2016

I managed to downgrade ohai < 4.0.0 version and the nginx cookbook went fine.
Thanks for pointing this out.

chef-delivery pushed a commit to chef/omnitruck that referenced this issue Jul 19, 2016
This is a transitive dep brought in by the nginx cookbook. See the
following PRs for full details on why this is required:
sous-chefs/nginx#419
priestjim/chef-openresty#47

Signed-off-by: Seth Chisamore <schisamo@chef.io>
chef-delivery pushed a commit to chef/omnitruck that referenced this issue Jul 19, 2016
This is a transitive dep brought in by the nginx cookbook. See the
following PRs for full details on why this is required:
sous-chefs/nginx#419
priestjim/chef-openresty#47

Signed-off-by: Seth Chisamore <schisamo@chef.io>
@gkope
Copy link

gkope commented Jul 26, 2016

👍

@tas50
Copy link
Contributor

tas50 commented Aug 2, 2016

This is fixed with the constrain on Ohai 3.X in #422

@tas50
Copy link
Contributor

tas50 commented Aug 12, 2016

This particular issue has been pulled into the chef_nginx cookbook 2.8.0 release. The chef_nginx cookbook is a fork of this cookbook with many of the outstanding issues in the 2.7.6 release resolved. The release is backwards compatible with this cookbook outside of the name change, which obviously requires updating runlist and and metadata dependencies. I'd highly suggest giving it a try to see if this resolves you nginx cookbook woes.

https://github.com/chef-cookbooks/chef_nginx
https://supermarket.chef.io/cookbooks/chef_nginx#changelog

@tas50
Copy link
Contributor

tas50 commented Sep 17, 2017

Thanks for opening this issue. Just today we merged the changes from the chef_nginx fork of this cookbook back to master here. It’s a pretty huge change set and includes over a year of active development that resulted in several major releases. I think there’s a very high chance that this issue has been resolved with that work and at this point I’m going to close this issue out. I’d encourage you to checkout the master branch and please open this issue back up if you’re still having the problem there.

Here’s the changes that were just merged in: #435

@tas50 tas50 closed this as completed Sep 17, 2017
@lock
Copy link

lock bot commented Apr 25, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Apr 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants