I am new to chef and started writing a simple recipe using the Users library. My Berksfile:
name@name:~/chef-repo$ cat Berksfile
site :opscode
cookbook "users"
and then I ran:
berks install
and my cookbooks:
name@name:~/chef-repo$ ls cookbooks/
users
finally my recipe:
name@name:~/chef-repo$ cat blah-users.rb
include_recipe "users"
users_manage "blah-dev" do
group_id 1001
action [ :remove, :create ]
end
when I appply I get an error:
name@name:~/chef-repo$ chef-apply blah-users.rb
[2015-05-04T09:05:48-04:00] FATAL: Stacktrace dumped to /home/name/.chef/cache/chef-stacktrace.out
[2015-05-04T09:05:48-04:00] FATAL: NoMethodError: undefined method `unreachable_cookbook?' for nil:NilClass
I am fairly certain that the include_recipe "users" is the problem (at least the first). I also find this line Stacktrace dumped to /home/name/.chef/cache/chef-stacktrace.out interesting as there isn't a file at that location.
I have tried with and without sudo. So I don't think it is a permissions issue.
I am running a local install of chef server 12.3 which looks to be functioning fine...
Thanks
~/chef-repo$ sudo chef-apply blah-users.rb -l debug
[2015-05-04T13:17:50-04:00] DEBUG: Building node object for tbrown
[2015-05-04T13:17:50-04:00] DEBUG: Extracting run list from JSON attributes provided on command line
[2015-05-04T13:17:50-04:00] DEBUG: Applying attributes from json file
[2015-05-04T13:17:50-04:00] DEBUG: Platform is ubuntu version 14.04
[2015-05-04T13:17:50-04:00] INFO: Run List is []
[2015-05-04T13:17:50-04:00] INFO: Run List expands to []
[2015-05-04T13:17:50-04:00] DEBUG: Loading Recipe users via include_recipe
[2015-05-04T13:17:50-04:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2015-05-04T13:17:50-04:00] DEBUG: NoMethodError: undefined method `unreachable_cookbook?' for nil:NilClass
/opt/chefdk/embedded/apps/chef/lib/chef/run_context.rb:257:in `unreachable_cookbook?'
/opt/chefdk/embedded/apps/chef/lib/chef/run_context.rb:155:in `load_recipe'
/opt/chefdk/embedded/apps/chef/lib/chef/run_context.rb:142:in `block in include_recipe'
/opt/chefdk/embedded/apps/chef/lib/chef/run_context.rb:141:in `each'
/opt/chefdk/embedded/apps/chef/lib/chef/run_context.rb:141:in `include_recipe'
/opt/chefdk/embedded/apps/chef/lib/chef/dsl/include_recipe.rb:26:in `include_recipe'
blah-users.rb:1:in `run_chef_recipe'
/opt/chefdk/embedded/apps/chef/lib/chef/application/apply.rb:168:in `instance_eval'
/opt/chefdk/embedded/apps/chef/lib/chef/application/apply.rb:168:in `run_chef_recipe'
/opt/chefdk/embedded/apps/chef/lib/chef/application/apply.rb:180:in `run_application'
/opt/chefdk/embedded/apps/chef/lib/chef/application/apply.rb:193:in `run'
/opt/chefdk/embedded/apps/chef/bin/chef-apply:25:in `<top (required)>'
/usr/bin/chef-apply:51:in `load'
/usr/bin/chef-apply:51:in `<main>'
[2015-05-04T13:17:50-04:00] FATAL: NoMethodError: undefined method `unreachable_cookbook?' for nil:NilClass
chef-apply blah-users.rb -l debug
. At all I'm unsure chef-apply could be used with dependency (i.e require recipe from another cookbook) as it is intended to run small portion of internal resources only and there's no cookbook loading (and so no read ofmetadata.rb
as there's none). Best workaround I can think of is to use chef-solo or chef-zero (See docs.chef.io for exented informations) with a cookbook having the correct dependency in it'smetadata.rb
file. – Tensibai