4

I have a set of cookbooks for provisioning web and SQL servers and they are currently used in our continuous deployment pipeline. I would like developers to be able to use the same cookbooks for setting up their local development environments without registering each development machine with the chef server. It appears that chef zero can be used to accomplish this, however I'm having some troubles getting started with it.

I have a chef-repo folder with my cookbooks in it and I was following the steps in this article.

PS C:\Temp\chef-repo> tree .
Folder PATH listing
Volume serial number is 3E77-463C
C:\TEMP\CHEF-REPO
└───cookbooks
    └───test
        └───recipes
PS C:\Temp\chef-repo> cat .\cookbooks\test\recipes\default.rb
file "C:\Temp\test.log" do
  content 'HELLO WORLD'
end

However, when I run chef-client -z -o test it doesn't seem to be able to find my cookbooks.

This is the error I get:

Starting Chef Client, version 11.16.0
[2014-09-25T10:17:37-05:00] WARN: Run List override has been provided.
[2014-09-25T10:17:37-05:00] WARN: Original Run List: []
[2014-09-25T10:17:37-05:00] WARN: Overridden Run List: [recipe[test]]
resolving cookbooks for run list: ["test"]

================================================================================
Error Resolving Cookbooks for Run List:
================================================================================

Missing Cookbooks:
------------------
No such cookbook: test

Expanded Run List:
------------------
* test


Running handlers:
[2014-09-25T10:17:37-05:00] ERROR: Running exception handlers
Running handlers complete
[2014-09-25T10:17:37-05:00] ERROR: Exception handlers complete
[2014-09-25T10:17:37-05:00] FATAL: Stacktrace dumped to C:/Users/username/.chef/local-mode-cache/cache/chef-stacktrace.out
Chef Client failed. 0 resources updated in 25.375311 seconds
[2014-09-25T10:17:38-05:00] FATAL: Net::HTTPServerException: 412 "Precondition Failed "

I run this command from C:\Temp\chef-repo, which is the root of my chef repository folder. I've also tried modifying my %USERPROFILE%\.chef\knife.rb to contain the following settings:

cookbook_path [
  "C:\Temp\chef-repo\cookbooks"
]
local_mode true
node_name "Chef.example.com"

What am I doing wrong?

2 Answers 2

4

What is going wrong is that your conf specify

cookbook_path [
  "C:\Temp\chef-repo\cookbooks"
]

which will be probably interpreted as C:Tempchef-repocookbooks by ruby when loading the knife.rb replace the \ by / or double them \\

The knife.rb is a ruby file and parsed as ruby code.

As with many programming language the \ is used to escape the next character.

Edit for precision:

Always use forward slashes, you'll avoid mistakes and chef takes care of replacing them with properly escaped backslashes when needed in copy commands etc.

The only place you wold use backslashes would be a batch resource with heredoc syntax and maybe you'll have to escape them anyway (unsure for the escaping need)

0
2

This doesn't answer your question exactly...I got around this by having developers use a vagrant vm that is in a "vagrant" chef environment, which closely matches the run_list(s) of the dev/qa/prod environments with some minor exceptions. Each one has the same node name as far as the chef server is concerned and so sidesteps having to register each machine.

1
  • Thanks for the suggestion. Something to think about anyway, but really hoping for a serverless solution so that the chef recipes can be delivered as part of the build drop along with the other build artifacts and just executed as part of the deploy. Sep 26, 2014 at 14:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.