chef / chef-cli

The 'chef' command line tool included in Chef Workstation
Apache License 2.0
16 stars 24 forks source link

Document chefdk.* settings #54

Open jblaine opened 8 years ago

jblaine commented 8 years ago

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 = 'me@myorg.com' cookbook_license = 'our_chosen_license' cookbook_copyright = 'whatever'

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

smacfarlane commented 8 years ago

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!

jblaine commented 8 years ago

@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 = 'jblaine@our.org'
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:
smacfarlane commented 8 years ago

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

jblaine commented 8 years ago

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).

smacfarlane commented 8 years ago

Great! Glad I could help.

gregkare commented 4 years ago

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            'mail@example.com`

Should I create a separate issue about this?