17

I have my Chef cookbooks stored in chef/cookbooks/ folder. When running kitchen converge I am still getting notice

Berksfile, Cheffile, cookbooks/, or metadata.rb not found so Chef will run with effectively no cookbooks. Is this intended?

I tried many options, for example:

suites:
  - name: default
    run_list: recipe[git]
    cookbook_path: "chef/cookbooks"

but I can't find the proper solution. How to specify the cookbooks' and roles' paths?

tsusanka
  • 4,801
  • 7
  • 36
  • 42
  • Are you running test-kitchen within the folder of a cookbook or in your repo containing multiple cookbooks? Should be the first one.. – StephenKing Apr 29 '14 at 15:10
  • It's the latter. My goal is to test all the cookbooks together. I mean to make sure the node was provisioned well and everything is up and running. I don't need to test one cookbook (because I use the community ones anyway). Is that a wrong approach? – tsusanka Apr 29 '14 at 15:16
  • 1
    Yes, to my knowledge, t-k is for testing one particular cookbook (that can depend on others). – StephenKing Apr 29 '14 at 15:21
  • 1
    Ok, is there any other sophisticated approach to test the whole infrastructure? Or the admins usually simply "believe" it all works together if the parts do? – tsusanka Apr 29 '14 at 21:20

3 Answers3

16

You'll want to put the path in your berksfile, which will likely end up looking like so..

source 'https://supermarket.chef.io'
cookbook 'cookbookname', path: 'relative/or/absolute/path/to/cookbook/directory'

The berksfile is also used by chef when you deploy your code so it helps if your relative file structure is the same on your machine as it is on your chef server (i.e. all cookbooks share a directory so your berksfile can use the path '../cookbookname')

JackChance
  • 520
  • 3
  • 11
  • This solved the problem for me. I was running .kitchen.yml from a directory outside of my cookbook in another project, with references pointing back to values inside the cookbook. – comjf Aug 21 '15 at 14:56
  • Thank you very much! come again! – Mihado Jun 01 '16 at 00:31
3

You want to set it in the provisioner section:

provisioner:
  name: chef_zero
  require_chef_omnibus: 11.12.2
  cookbook_path: whatever/path/to/cookbooks
sethvargo
  • 26,739
  • 10
  • 86
  • 156
  • Still can't get it work, do u have a minute to have a fast look into my bash log? https://gist.github.com/tsusanka/8cdf9c7828a85cd94889 the think is the files aren't even copied to the OS – tsusanka Apr 30 '14 at 06:25
  • It looks like you are already using Berkshelf - why use a cookbook_path at all? – sethvargo Apr 30 '14 at 13:30
  • 1
    Thx for the reply. I decided to version the cookbooks downloaded via Berkshelf. I guess that's unnecessary, but anyway even if I use Berkshelf, I still have my own non-community cookbooks located in `chef/cookbooks` which I need to be added. – tsusanka Apr 30 '14 at 14:01
  • 2
    If you are using Berkshelf why not just put it in there. Add a line like this to your `Berksfile`: `cookbook 'name', path: '/local/path/to/cookbook'` – jarsever Aug 06 '14 at 20:56
  • @jarsever he would need to do that with each one – sethvargo Aug 06 '14 at 22:51
  • @sethvargo you are correct. I guess the only other easy option is to change the Berkshelf cookbook location or do what we do and set up a [berkshelf-api](https://github.com/berkshelf/berkshelf-api) server. – jarsever Aug 07 '14 at 02:46
  • Late to the party, hope this might help someone, using chef dk 2.6.2+ and chef-client 13.12.3 can use ------------------ provisioner: name: chef_zero product_name: chef product_version: 12.22.3 – Tim Sep 03 '20 at 21:47
1

Set up a top level Berksfile where you have .kitchen.yml that contains a reference to the cookbooks you're testing. Each cookbook will declare their dependencies and berks install at the top level will ensure you have everything installed.

(I just ran into the same issue starting out with chefdk 0.4).

syrnick
  • 497
  • 3
  • 6
  • I had this problem, where the berkshelf provisioning wouldn't happen when trying to run test kitchen. This was the solution, so commenting about that here, to help others find the same solution. – BeepDog Jun 13 '18 at 21:01