chef-cli icon indicating copy to clipboard operation
chef-cli copied to clipboard

Document chefdk.* settings

Open jblaine opened this issue 9 years ago • 6 comments

UPDATE: See end of thread first. This was originally an issue requesting the following.

Since 'knife cookbook create' is largely (or will be) deprecated, this is my plea for traditional behavior to be restored where one can use commands that take their default values from $HOME/.some_chef_file (a-la 'knife cookbook create' and knife.rb settings).

$HOME/.chef_cli.rb and something like:

cookbook_email = '[email protected]' cookbook_license = 'our_chosen_license' cookbook_copyright = 'whatever'

Or... some way to set attributes and sanely reference include_recipe "#{chefdk_stock_code_generator}"

jblaine avatar Apr 12 '16 19:04 jblaine

I had the same problem recently, and found that you could set the following in ~/.chef/config.rb

if defined?(ChefDK)
  chefdk.generator.license 'LICENSE'
  chefdk.generator.email 'EMAIL'
  chefdk.generator.copyright_holder 'ME'
end

I wrapped it in if defined?(ChefDK) because I have some older knife plugins that puke on that syntax. I also pasted all my knife.rb settings into that file, and set it to be a symlink to config.rb. Not sure if this is the right solution, but so far I haven't hit any problems. There's also a chefdk.generator_cookbook option you can set.

Hope this helps!

smacfarlane avatar Apr 12 '16 20:04 smacfarlane

@smacfarlane Thanks for the information. What ChefDK version are you using? I get an exception after adding that block with 0.12.0 from the stable release page.

if defined?(ChefDK)
  chefdk.generator.license = 'reserved'
  chefdk.generator.copyright_holder = 'OURORG'
  chefdk.generator.email = '[email protected]'
end

chef generate cookbook noodle:

  * template[/afs/rcf/user/jblaine/rcf-chef/noodle/spec/unit/recipes/default_spec.rb] action create_if_missing

    ================================================================================
    Error executing action `create_if_missing` on resource 'template[/afs/rcf/user/jblaine/rcf-chef/noodle/spec/unit/recipes/default_spec.rb]'
    ================================================================================

    Chef::Mixin::Template::TemplateError
    ------------------------------------
    undefined method `gsub' for nil:NilClass

    Resource Declaration:
    ---------------------
    # In /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-dk-0.12.0/lib/chef-dk/skeletons/code_generator/recipes/cookbook.rb

     88: template "#{cookbook_dir}/spec/unit/recipes/default_spec.rb" do
     89:   source "recipe_spec.rb.erb"
     90:   helpers(ChefDK::Generator::TemplateHelper)
     91:   action :create_if_missing
     92: end
     93:

jblaine avatar Apr 12 '16 20:04 jblaine

I think I'm on 0.12.0 (not at my workstation atm).

That error is probably caused by not setting the license to one of the licenses defined here: https://github.com/chef/chef-dk/blob/master/lib/chef-dk/generator.rb#L73-L152

smacfarlane avatar Apr 12 '16 21:04 smacfarlane

Yup. Changing it to all_rights fixed things. Looks like a blog post is in my future tonight to share this buried information (with attribution to you).

jblaine avatar Apr 12 '16 21:04 jblaine

Great! Glad I could help.

smacfarlane avatar Apr 12 '16 22:04 smacfarlane

On ChefDK version 4.6.35 (as well as previous versions) I can only make this work by having the chefdk.generator values set in a config.rb at the root of the current directory. Having them in .chef/config.rb or ~/.chef/config.rb makes chef generate cookbook COOKBOOK_NAME use the default values in the generated cookbook's metadata.rb

chefdk.generator.copyright_holder 'Copyright Holder'
chefdk.generator.license          'mit'
chefdk.generator.email            '[email protected]`

Should I create a separate issue about this?

gregkare avatar Dec 27 '19 10:12 gregkare