Skip to content

Instantly share code, notes, and snippets.

@atomic-penguin
Created February 5, 2013 20:07
Show Gist options
  • Select an option

  • Save atomic-penguin/4717224 to your computer and use it in GitHub Desktop.

Select an option

Save atomic-penguin/4717224 to your computer and use it in GitHub Desktop.
chef > if node['kernel']['modules'].has_key('ip6tables')
chef ?> puts "true"
chef ?> end
NoMethodError: Undefined node attribute or method `has_key' on `node'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.0.0/lib/chef/node/immutable_collections.rb:164:in `method_missing'
from (irb):4
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.0.0/lib/chef/shell.rb:73:in `block in start'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.0.0/lib/chef/shell.rb:72:in `catch'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.0.0/lib/chef/shell.rb:72:in `start'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.0.0/bin/shef:35:in `<top (required)>'
from /usr/bin/shef:23:in `load'
from /usr/bin/shef:23:in `<main>'
@atomic-penguin

Copy link
Copy Markdown
Author

This worked on Chef <= 10.X.

On Chef >= 11.X it seems hash methods are not allowed on node attributes.

EDIT: Requires using a ? on the .has_key? method call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment