Search code examples
vagrantchef-infrachef-recipechef-solo

Chef application_java cookbook - uninitialized constant Chef::DSL


I have a problem with application_java cookbook. I added recipe into application_java cookbook to deploy my .war archive to Tomcat. This is how it looks like:

case node['platform']
when 'debian', 'ubuntu'
  include_recipe 'apt'
end
include_recipe 'java' # Need described below

application 'ensembleAPI' do
  path         "/var/lib/tomcat7/webapps/ensembleRestApi.war"
  owner "root"
  group "root"
  mode "0777"
  repository   'ensembleRestApi.war'
scm_provider Chef::Provider::File::Deploy

java_webapp
tomcat
end

I think this is OK. But when I run all process with vagrant up it ends with following error

NameError
---------
uninitialized constant Chef::DSL
Cookbook Trace:
---------------
  /tmp/vagrant-chef-1/chef-solo-1/cookbooks/application_java/providers/java_webapp.rb:20:in `class_from_file'

My chef version is 11.10.2.


Solution

  • You need to use Chef 11+. The error:

    NameError
    ---------
    uninitialized constant Chef::DSL
    

    Comes from this line in the cookbook...

    include Chef::DSL::IncludeRecipe
    

    The Chef::DSL class doesn't exist in earlier versions of Chef. If you're using Vagrant, it sounds like you may be using a Vagrant box that has Chef preinstalled at an older version. I suggest looking into Chef's "Bento" project, which has newer base boxes without Chef installed, that you can use with the "vagrant-omnibus" plugin to get the version of Chef you want to use via Chef's omnibus packages.