windowschef-infrachef-solochef-windows

How to run chef without chef server (chef solo/chef zero)


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?


Solution

  • 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)