2

I can't figure out how to run roles in a run list in test kitchen.

I did a knife download roles to my chef repo (C:\.chef\roles).

I also did a knife download cookbooks to c:\.chef\cookbooks

Here is the .kitchen.yml for a cookbook I want to test which I plan to run with a particular role (C:\.chef\cookbooks\mybook\.kitchen.yml):

---
driver:
  name: hyperv
  parent_vhd_folder: c:\HyperV\VHDs\
  parent_vhd_name: 2012R2_Fresh_Gen1.vhdx
  vm_switch: NAT
  memory_startup_bytes: 2GB

provisioner:
  name: chef_zero
  roles_path: c:\.chef\roles

transport:
  password: pass123

platforms:
  - name: windows-2012r2

suites:
  - name: default
    run_list:
      - role[myrole]
    attributes:

When I run a kitchen converge I get "No such cookbook:" error for cookbooks that are in that role.

How do I get test kitchen to find those cookbooks? I tried adding a - cookbooks line to my .kitchen.yml with the path of all the necessary cookbooks I have on my workstation, but this did not work- I also think I should be doing this with berkshelf instead?

red888
  • 27,709
  • 55
  • 204
  • 392

1 Answers1

1

You'll need to tell Test Kitchen where to get your cookbooks. The easiest way to do this is Berkshelf (or maybe a Policyfile). Put a Berksfile next to the Kitchen config and show it where to get all the cookbooks (supermarket, local paths, chef server, etc).

coderanger
  • 52,400
  • 4
  • 52
  • 75
  • Can I put my cookbooks path in the berksfile? I only see examples for specifying individual cookbooks in the berksfile – red888 Jul 29 '16 at 20:55
  • Use a loop: `Dir[File.expand_path('../cookbooks/*', __FILE__)].each {|path| cookbook File.basename(path), path: path }` or similar depending on your layout. – coderanger Jul 29 '16 at 21:26
  • Hmm I dropped that in the Berkshelf file I have in the cookbook and I still get no such cookbook – red888 Jul 29 '16 at 21:43
  • Run a `berks install` and look at the generated lockfile. – coderanger Jul 29 '16 at 21:47
  • After running berks install it looks like it hasn't updated the lock file with any more cookbooks. And all my cookbooks are located in the same place (../cookbooks from this cookbook is where they are). Do I need that code in metadata.rb too? – red888 Jul 29 '16 at 21:49
  • If I do `cookbook 'mybook'` in the berksfile it does install it and update the lock file when doing `berks install` – red888 Jul 29 '16 at 21:53