Using Cookbooks in Environments?

I am wanting to test a cookbook in an environment called dev1 which has the same name as a cookbook in _default. The cookbook name is test. Here is my problem

  1. I uploaded the cookbook using “knife cookbook upload test -E dev1”
  2. I ran “knife cookbook show test 0.1.0” and it doesn’t list the environment
  3. I added the node to the run_list of test but the node is in the _default environment. I was expecting an error but it got added successfully.
  4. I then uploaded the test cookbook “knife cookbook upload test”
  5. When I run knife cookbook list I only see one (I assumed I would have two cookbooks one for _default and one for dev1)

The reason for this testing is because I have a cookbook that I have made changes to and want to test it in dev1 and want to make sure that it doesn’t get pushed out to production. This cookbook has the same name windows_hardening. How can I make sure this doesn’t happen?

Use chef-solo to test the development cookbook, locally, without ever uploading it to the chef server. Alternatively, give it an older cookbook version number, load that, and set the dev environment to use the older cookbook version. Or give it a different cookbook name altogether.

Chef does not have a great concept of “this cookbook is loaded on the server for only this environment”. You can lock down a version number in the environment, and in the “requires” settings in a placeholder cookbook pretty easily, but resolving dependencies this way can become an adventure. There was a while, when yum and nagios got updated and broke backwards compatibility without a major release number change, that I had to upload multiple sets of the same cookbooks reliably, especially to support CentOS 5 and CentOS 6 based deployments. I used to create a subdirectory with distinct Berkshelf settings to organize and upload different versions of cookbooks from the same source tree. It became quite an adventure!!!