0

Asked a similar question on this, but realized my problem is more with conceptualizing how this can work.

I've read a bunch of articles, but I'm still super confused.

Here is what I am doing now:

I apply a set of base roles to all my nodes (windows_base, linux_base, etc). These roles apply recipes that do things like set the time zone, join to AD and do other config that is required on all servers regardless of their purpose.

Now I have my other cookbooks that install apps and make specific configuration changes for specific purposes. While these cookbooks should usually "work" (meaning won't throw errors) without needing the base roles run first they still might depend on the base roles to do some initial server config and might not work correctly without that applied first.

So when I test one of my cookbooks in test kitchen I will sometimes want to include a base role in the run list (prior to the cookbooks recipes I'm testing).

I downloaded my roles from my server with knife download and specified them in the kitchen.yml via roles_path but apparently I still need to tell test kitchen where to get my cookbooks inside the role?

Now you can see the previous question I asked it was suggested I use berkshelf, but if I do that I need to specify ALL the recipes from the base roles in the berksfile of the cookbook I am testing right? That doesn't make sense to me because I don't need to do this when applying a role to a node via Chef server. I also don't want all these dependencies in my berksfile because like I said they sort of depend on the roles, but not necessarily.

How do I use roles in test Kitchen like they are used on Chef server- meaning I just apply a role to a nodes run list.

I should say I also tried defining the cookbooks path (cookbooks_path:) in kitchen.yml but this didn't work ether.

This is my .kitchen.yml

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

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

transport:
  password: myPass123$

platforms:
  - name: windows-2012r2

suites:
  - name: default
    run_list:
      - role[linux_base]
    attributes:
Community
  • 1
  • 1
red888
  • 27,709
  • 55
  • 204
  • 392

1 Answers1

2

The answer is still the same as last time, you have to show Kitchen how to get all of your cookbooks. You can do this either via Berkshelf, Librarian, Policyfiles, or a static path. The relevant code is in https://github.com/test-kitchen/test-kitchen/blob/master/lib/kitchen/provisioner/chef/common_sandbox.rb if you want to see 100% of what is supported. There is nothing automatic like with a Chef Server, because this is presumed be for development and as such can't rely on a single artifact repo.

coderanger
  • 52,400
  • 4
  • 52
  • 75
  • So would it work/make sense to set the `cookbooks_path` in my `.kitchen.yml` to `C:\Users\me\.berkshelf` (my berkshelf folder)? Or does berkshelf override `cookbooks_path` in `.kitchen.yml`? – red888 Aug 02 '16 at 19:16
  • 1
    No, the Berkshelf storage folder is not organized in a way that Chef can read it. Kitchen runs `berks vendor` for you to a temp folder to output things in the correct format. – coderanger Aug 02 '16 at 19:55