Configuring chefdk

· by Artem Sidorenko · Read in about 2 min · (216 words)

Chef Development Kit contains a chef-dk gem with chef executable. chef generate is a pretty usefull command for generation of skelettons. Per default the information like author, license or email looks like this:

$ cat testcookbook/metadata.rb
name 'testcookbook'
maintainer 'The Authors'
maintainer_email 'you@example.com'
license 'all_rights'
...

How to get your own data instead of this defaults?

Configuration of own license, email and name

Chefdk does not have yet its own configuration file, it extends the usual chef configs with its own parameters.

Add following lines to ~/.chef/config.rb:

# ~/.chef/config.rb
# we use if to check if we are in the chef-dk context.
# otherwise you can get exceptions because of undefined chefdk.generator (e.g. in knife)
if chefdk.generator
  chefdk.generator.license = 'mit'
  chefdk.generator.copyright_holder = 'Cool author'
  chefdk.generator.email = 'contact@example.com'
end

Be careful with a license: you have to use the exact license names like they are in lib/chef-dk/generator.rb.

More customization

chef generate uses a chef cookbook to generate the files and content. If you need more customization or some special things, you can create your own generator cookbook (see chef-dk for an example). To use it with chef-dk you will need following configuration in ~/.chef/config.rb:

# ~/.chef/config.rb
chefdk.generator_cookbook = '/path/to/your/cookbook' if chefdk

The cookbook name in metadata.rb should be the same like the directory name containing the cookbook.