Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chef generate cookbook with a generated generator fails #8

Closed
jerryaldrichiii opened this issue Jun 18, 2019 · 7 comments
Closed

Chef generate cookbook with a generated generator fails #8

jerryaldrichiii opened this issue Jun 18, 2019 · 7 comments
Labels
Status: Help Wanted An issue that needs help from a contributor. Triage: Confirmed Indicates and issue has been confirmed as described.

Comments

@jerryaldrichiii
Copy link
Contributor

Description

NOTE: Possibly a duplicate of #633

Generating a generator then using chef generate cookbook foobar -g that_generator fails with:

Generating cookbook foobar
ERROR: Could not find cookbook(s) to satisfy run list ["recipe[example_generator::cookbook]"] in /home/vagrant/foo
Caused by: (Chef::Exceptions::CookbookNotFound) Cookbook example_generator not found. If you're loading example_generator from another cookbook, make sure you configure the dependency in your metadata
[vagrant@localhost foo]$ chef generate cookbook foobar -g ../example_generator
Generating cookbook foobar
[2019-06-17T23:59:12+00:00] WARN: Found a directory foo in the cookbook path, but it contains no cookbook files. skipping.
ERROR: Chef failed to converge: undefined method `metadata' for nil:NilClass from file /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.0.300/lib/chef/cookbook_loader.rb:99:in `load_cookbook'
Caused by: (NoMethodError) undefined method `metadata' for nil:NilClass

Oddly, moving the generator in to an empty directory makes it work.

ChefDK Version

Chef Development Kit Version: 4.0.60
chef-client version: 15.0.300
delivery version: master (9d07501a3b347cc687c902319d23dc32dd5fa621)
berks version: 7.0.8
kitchen version: 2.2.5
inspec version: 4.3.2

Platform Version

CentOS 6.9

Replication Case

# This fails
curl -L https://omnitruck.chef.io/install.sh | sudo bash -s -- -P chefdk
chef generate generator example_generator
chef generate cookbook foobar -g example_generator

# This makes it work
mkdir example_dir
mv example_generator
chef generate cookbook foobaz -g example_generator
@jerryaldrichiii
Copy link
Contributor Author

jerryaldrichiii commented Jun 18, 2019

Another nuance. The directory that moving the generator too must be empty (or contain only generators?)

[vagrant@localhost ~]$ mkdir generators
[vagrant@localhost ~]$ mkdir generators/not_a_generator
[vagrant@localhost ~]$ chef generate generator generators/example_generator
Copied built-in generator cookbook to /home/vagrant/generators/example_generator
Add the following to your config file to enable it:
  chefdk.generator_cookbook "/home/vagrant/generators/example_generator"
[vagrant@localhost ~]$ chef generate cookbook example_cookbook -g generators/example_generator
Generating cookbook example_cookbook
[2019-06-18T00:50:52+00:00] WARN: Found a directory not_a_generator in the cookbook path, but it contains no cookbook files. skipping.
ERROR: Chef failed to converge: undefined method `metadata' for nil:NilClass from file /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.0.300/lib/chef/cookbook_loader.rb:99:in `load_cookbook'
Caused by: (NoMethodError) undefined method `metadata' for nil:NilClass
[vagrant@localhost ~]$```

@tyler-ball
Copy link
Contributor

Thanks @jerryaldrichiii! We're going to move this issue to the https://github.com/chef/chef-cli repo since that is the new place for tracking issues with the chef command. This is part of our ongoing work to separate out the packaging of the Chef Workstation product from the chef command itself. We will track this issue and the work in that new repo.

@tyler-ball tyler-ball transferred this issue from chef-boneyard/chef-dk Jul 8, 2019
@tyler-ball tyler-ball added Aspect: Correctness Triage: Confirmed Indicates and issue has been confirmed as described. labels Jul 8, 2019
@tyler-ball tyler-ball added the Status: Help Wanted An issue that needs help from a contributor. label Aug 12, 2019
@ressafri
Copy link

ressafri commented Sep 5, 2019

I'm having exactly the same issue.

@zmaupin
Copy link

zmaupin commented Sep 12, 2019

I am having the same problem.

Version:

 $ chef --version
ChefDK version: 4.4.1
Chef Infra Client version: 15.2.20
Chef InSpec version: 4.12.0
Test Kitchen version: 2.2.5
Foodcritic version: 16.1.1
Cookstyle version: 5.2.17

Environment:

macOS Mojave 10.14.6
Downloaded the code_generator from https://github.com/chef/chef-dk/tree/master/lib/chef-dk/skeletons/code_generator
I also tried using https://github.com/chef/chef-dk/tree/master/lib/chef-dk/skeletons/code_generator with the same errors.

Scenario:

I want to use chef generate cookbook my_cookbook -g code_generator/

Steps to Reproduce:

  • Build the code_generator with chef generate generator
  • Try to use the code_generator cookbook to generate a new cookbook chef generate cookbook my_cookbook -g code_generator/

Expected Result:

I expected a new cookbook built with the generator cookbook.

Actual Result:

 $ chef generate cookbook testcookbook1 -b -g code_generator/
Generating cookbook testcookbook1
- Ensuring correct cookbook content
[2019-09-12T10:57:56-04:00] WARN: Found a directory testcookbook1 in the cookbook path, but it contains no cookbook files. skipping.

================================================================================
Error executing action `create_if_missing` on resource 'template[/Users/zm/github/infraconfig/testcookbook1/metadata.rb]'
================================================================================

NoMethodError
-------------
undefined method `metadata' for nil:NilClass

Resource Declaration:
---------------------
# In /Users/zm/github/infraconfig/code_generator/recipes/cookbook.rb

 25: template "#{cookbook_dir}/metadata.rb" do
 26:   helpers(ChefDK::Generator::TemplateHelper)
 27:   variables(
 28:     spdx_license: spdx_license
 29:   )
 30:   action :create_if_missing
 31: end
 32:

Compiled Resource:
------------------
# Declared in /Users/zm/github/infraconfig/code_generator/recipes/cookbook.rb:25:in `from_file'

template("/Users/zm/github/infraconfig/testcookbook1/metadata.rb") do
  action [:create_if_missing]
  default_guard_interpreter :default
  source "metadata.rb.erb"
  helper_modules [ChefDK::Generator::TemplateHelper]
  declared_type :template
  cookbook_name :code_generator
  recipe_name "cookbook"
  variables {:spdx_license=>"All Rights Reserved"}
  path "/Users/zm/github/infraconfig/testcookbook1/metadata.rb"
  owner nil
  group nil
  mode nil
  verifications []
end

System Info:
------------
chef_version=15.2.20
ruby=ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin16]
program_name=/usr/local/bin/chef
executable=/opt/chefdk/bin/chef

ERROR: Chef Infra failed to converge: template[/Users/zm/github/infraconfig/testcookbook1/metadata.rb] (code_generator::cookbook line 25) had an error: NoMethodError: undefined method `metadata' for nil:NilClass from file /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.2.20/lib/chef/cookbook_loader.rb:99:in `load_cookbook'
Caused by: (NoMethodError) template[/Users/zm/github/infraconfig/testcookbook1/metadata.rb] (code_generator::cookbook line 25) had an error: NoMethodError: undefined method `metadata' for nil:NilClass

@subhro
Copy link

subhro commented May 22, 2020

#61

@jerryaldrichiii
Copy link
Contributor Author

Closing this as I do not support Chef's contract with ICE and no longer care about the result of this ticket.

@ashwell123
Copy link

i have same issue how can i solve this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Help Wanted An issue that needs help from a contributor. Triage: Confirmed Indicates and issue has been confirmed as described.
Projects
None yet
Development

No branches or pull requests

7 participants