Chef undefined method ‘content_source’ error

The Problem

If you’re running chef v2.1 you may have run into this bug. I’m running CentOS 6 in a VM and received the error when running “chef generate template webserver index.html”. This was my resulting error code:

/opt/chefdk/embedded/apps/chef-dk/lib/chef-dk/skeletons/code_generator/recipes/template.rb:19:in `from_file’: undefined method `content_source’ for # (NoMethodError)
from /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.0.0.alpha.1/lib/chef/mixin/from_file.rb:30:in `instance_eval’
from /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.0.0.alpha.1/lib/chef/mixin/from_file.rb:30:in `from_file’
from /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.0.0.alpha.1/lib/chef/cookbook_version.rb:245:in `load_recipe’
from /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.0.0.alpha.1/lib/chef/run_context.rb:166:in `load_recipe’
from /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.0.0.alpha.1/lib/chef/run_context/cookbook_compiler.rb:140:in `block in compile_recipes’
from /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.0.0.alpha.1/lib/chef/run_context/cookbook_compiler.rb:138:in `each’
from /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.0.0.alpha.1/lib/chef/run_context/cookbook_compiler.rb:138:in `compile_recipes’
from /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.0.0.alpha.1/lib/chef/run_context/cookbook_compiler.rb:75:in `compile’
from /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.0.0.alpha.1/lib/chef/run_context.rb:89:in `load’
from /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-12.0.0.alpha.1/lib/chef/policy_builder/expand_node_object.rb:73:in `setup_run_context’
from /opt/chefdk/embedded/apps/chef-dk/lib/chef-dk/chef_runner.rb:40:in `run_context’
from /opt/chefdk/embedded/apps/chef-dk/lib/chef-dk/chef_runner.rb:36:in `converge’
from /opt/chefdk/embedded/apps/chef-dk/lib/chef-dk/command/generator_commands/cookbook_code_file.rb:47:in `run’
from /opt/chefdk/embedded/apps/chef-dk/lib/chef-dk/command/generate.rb:82:in `run’
from /opt/chefdk/embedded/apps/chef-dk/lib/chef-dk/command/base.rb:57:in `run_with_default_options’
from /opt/chefdk/embedded/apps/chef-dk/lib/chef-dk/cli.rb:66:in `run’
from /opt/chefdk/embedded/apps/chef-dk/bin/chef:25:in `’
from /usr/bin/chef:40:in `load’
from /usr/bin/chef:40:in `’

Fix Action

I downloaded the insofar unreleased v2.2 source here to the desktop. I then did the following:

tar xf <name_of_archive>
cd chef-dk-master/
cp -r * /opt/chefdk/embedded/apps/chef-dk/

That took care of it for me. Hope this helps.

Leave a Reply