Trouble configuring and running chef-zero


#1

Hello chefizens,

I’m having some difficulty configuring and running chef-zero.

I’m not using vagrant in this case. What I want to do is to clone my chef git
repo on a test host, and run chef-zero locally on that host against a cookbook.
I have 2 directories that contain cookbooks in my chef-repo. Thus I want to
configure a cookbook_path in a config file.

I’m pointing chef-client (in local mode / “chef-zero” ) to a config file that
I think is correct (based on chef-solo experience), but I’m having problems. The
first problem occurs when chef-zero can’t find a “nodes” directory. The second
problem occurs when I work-around this “missing” nodes directory, and chef-zero
can’t find the cookbook.

Here’s the “solo.rb” config file I’m using:

$ cat ~/solo.rb
root = File.absolute_path(File.dirname(FILE))
cookbook_path [ root + ‘/chef-repo/cookbooks’, root + ‘/chef-repo/site-cookbooks’ ]
environment_path root + "/chef-repo/environments"
data_bag_path root + "/chef-repo/data_bags"
encrypted_data_bag_secret "/home/kallen/.chef/encrypted_data_bag_secret"
role_path root + “/chef-repo/roles”

(Yes, we have “site-cookbooks”. A pattern that got established early on. We’re
working to redesign our workflow :slight_smile:

$ cd ~/dev/git

The cookbook is in fact here:

ls -ld chef-repo/site-cookbooks/zero-test
drwxrwxr-x 5 kallen kallen 106 Jan 28 23:34 chef-repo/site-cookbooks/zero-test

$ chef-client -l debug -c ~/solo.rb -z -o “recipe[zero-test]”
…snip
[2014-01-28T23:11:46+00:00] DEBUG: Client key is unspecified - skipping registration
[2014-01-28T23:11:46+00:00] DEBUG: Building node object for dev-kallen.foobarbaz.net
[2014-01-28T23:11:46+00:00] DEBUG: Initiating GET to http://127.0.0.1:8889/nodes/dev-kallen.foobarbaz.net
[2014-01-28T23:11:46+00:00] DEBUG: ---- HTTP Request Header Data: ----
[2014-01-28T23:11:46+00:00] DEBUG: Accept: application/json
[2014-01-28T23:11:46+00:00] DEBUG: Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
[2014-01-28T23:11:46+00:00] DEBUG: GET nodes/dev-kallen.foobarbaz.net
[2014-01-28T23:11:46+00:00] DEBUG:
— RESPONSE (404) —
{
“error”: [
“Object not found: http://127.0.0.1:8889/nodes/dev-kallen.foobarbaz.net
]
}
— END RESPONSE —
[2014-01-28T23:11:46+00:00] DEBUG: ---- HTTP Status and Header Data: ----
[2014-01-28T23:11:46+00:00] DEBUG: HTTP 1.1 404 Not Found
[2014-01-28T23:11:46+00:00] DEBUG: content-type: application/json
[2014-01-28T23:11:46+00:00] DEBUG: server: chef-zero
[2014-01-28T23:11:46+00:00] DEBUG: connection: close
[2014-01-28T23:11:46+00:00] DEBUG: content-length: 100
[2014-01-28T23:11:46+00:00] DEBUG: ---- End HTTP Status/Header Data ----
[2014-01-28T23:11:46+00:00] INFO: HTTP Request Returned 404 Not Found: Object not found: http://127.0.0.1:8889/nodes/dev-kallen.foobarbaz.net
[2014-01-28T23:11:46+00:00] DEBUG: Initiating POST to http://127.0.0.1:8889/nodes
[2014-01-28T23:11:46+00:00] DEBUG: ---- HTTP Request Header Data: ----
[2014-01-28T23:11:46+00:00] DEBUG: Content-Type: application/json
[2014-01-28T23:11:46+00:00] DEBUG: Accept: application/json
[2014-01-28T23:11:46+00:00] DEBUG: Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
[2014-01-28T23:11:46+00:00] DEBUG: Content-Length: 181
[2014-01-28T23:11:46+00:00] DEBUG: POST nodes
— POST BODY —
{“name”:“dev-kallen.foobarbaz.net”,“chef_environment”:"_default",“json_class”:“Chef::Node”,“automatic”:{},“normal”:{},“chef_type”:“node”,“default”:
{},“override”:{},“run_list”:[]}
— END POST BODY —
[2014-01-28T23:11:46+00:00] ERROR: #<Errno::ENOENT: No such file or directory - /home/kallen/chef-repo/nodes>

So, for fun I create the dir /home/kallen/chef-repo/ and make a symlink from
/home/kallen/dev/chef-repo/nodes to /home/kallen/chef-repo/nodes. But why is it
looking in that location for the nodes directory? Is there a way to configure
the path?

This time, it’s able to affect URI /nodes/dev-kallen.foobarbaz.net because by
hand I created that directory outside of my dev workflow. But, this time it
errors on finding the cookbook.

$ chef-client -l debug -c ~/solo.rb -z -o “recipe[zero-test]”
…snip
[2014-01-28T23:14:15+00:00] DEBUG: Client key is unspecified - skipping registration
[2014-01-28T23:14:15+00:00] DEBUG: Building node object for dev-kallen.foobarbaz.net
[2014-01-28T23:14:15+00:00] DEBUG: Initiating GET to http://127.0.0.1:8889/nodes/dev-kallen.foobarbaz.net
[2014-01-28T23:14:15+00:00] DEBUG: ---- HTTP Request Header Data: ----
[2014-01-28T23:14:15+00:00] DEBUG: Accept: application/json
[2014-01-28T23:14:15+00:00] DEBUG: Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
[2014-01-28T23:14:15+00:00] DEBUG: GET nodes/dev-kallen.foobarbaz.net
[2014-01-28T23:14:15+00:00] DEBUG:
— RESPONSE (404) —
{
“error”: [
“Object not found: http://127.0.0.1:8889/nodes/dev-kallen.foobarbaz.net
]
}
— END RESPONSE —
[2014-01-28T23:14:15+00:00] DEBUG: ---- HTTP Status and Header Data: ----
[2014-01-28T23:14:15+00:00] DEBUG: HTTP 1.1 404 Not Found
[2014-01-28T23:14:15+00:00] DEBUG: content-type: application/json
[2014-01-28T23:14:15+00:00] DEBUG: server: chef-zero
[2014-01-28T23:14:15+00:00] DEBUG: connection: close
[2014-01-28T23:14:15+00:00] DEBUG: content-length: 100
[2014-01-28T23:14:15+00:00] DEBUG: ---- End HTTP Status/Header Data ----
[2014-01-28T23:14:15+00:00] INFO: HTTP Request Returned 404 Not Found: Object not found: http://127.0.0.1:8889/nodes/dev-kallen.foobarbaz.net
[2014-01-28T23:14:15+00:00] DEBUG: Initiating POST to http://127.0.0.1:8889/nodes
[2014-01-28T23:14:15+00:00] DEBUG: ---- HTTP Request Header Data: ----
[2014-01-28T23:14:15+00:00] DEBUG: Content-Type: application/json
[2014-01-28T23:14:15+00:00] DEBUG: Accept: application/json
[2014-01-28T23:14:15+00:00] DEBUG: Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
[2014-01-28T23:14:15+00:00] DEBUG: Content-Length: 181
[2014-01-28T23:14:15+00:00] DEBUG: POST nodes
— POST BODY —
{“name”:“dev-kallen.foobarbaz.net”,“chef_environment”:"_default",“json_class”:“Chef::Node”,“automatic”:{},“normal”:{},“chef_type”:“node”,“default”:{},“override”:{},“run_list”:[]}
— END POST BODY —
[2014-01-28T23:14:15+00:00] DEBUG:
— RESPONSE (201) —
{
“uri”: “http://127.0.0.1:8889/nodes/dev-kallen.foobarbaz.net
}
— END RESPONSE —
[2014-01-28T23:14:15+00:00] DEBUG: ---- HTTP Status and Header Data: ----
[2014-01-28T23:14:15+00:00] DEBUG: HTTP 1.1 201 Created
[2014-01-28T23:14:15+00:00] DEBUG: content-type: application/json
[2014-01-28T23:14:15+00:00] DEBUG: server: chef-zero
[2014-01-28T23:14:15+00:00] DEBUG: connection: close
[2014-01-28T23:14:15+00:00] DEBUG: content-length: 70
[2014-01-28T23:14:15+00:00] DEBUG: ---- End HTTP Status/Header Data ----
[2014-01-28T23:14:15+00:00] DEBUG: Extracting run list from JSON attributes provided on command line
[2014-01-28T23:14:15+00:00] DEBUG: Applying attributes from json file
[2014-01-28T23:14:15+00:00] DEBUG: Platform is amazon version 2013.09
[2014-01-28T23:14:15+00:00] WARN: Run List override has been provided.
[2014-01-28T23:14:15+00:00] WARN: Original Run List: []
[2014-01-28T23:14:15+00:00] WARN: Overridden Run List: [recipe[zero-test]]
[2014-01-28T23:14:15+00:00] INFO: Run List is [recipe[zero-test]]
[2014-01-28T23:14:15+00:00] INFO: Run List expands to [zero-test]
[2014-01-28T23:14:15+00:00] INFO: Starting Chef Run for dev-kallen.foobarbaz.net
[2014-01-28T23:14:15+00:00] INFO: Running start handlers
[2014-01-28T23:14:15+00:00] INFO: Start handlers complete.
[2014-01-28T23:14:15+00:00] DEBUG: Initiating POST to http://127.0.0.1:8889/reports/nodes/dev-kallen.foobarbaz.net/runs
…snip for brevity
[2014-01-28T23:14:15+00:00] DEBUG: Synchronizing cookbooks
resolving cookbooks for run list: [“zero-test”]
[2014-01-28T23:14:15+00:00] DEBUG: Initiating POST to http://127.0.0.1:8889/environments/_default/cookbook_versions
[2014-01-28T23:14:15+00:00] DEBUG: ---- HTTP Request Header Data: ----
[2014-01-28T23:14:15+00:00] DEBUG: Content-Type: application/json
[2014-01-28T23:14:15+00:00] DEBUG: Accept: application/json
[2014-01-28T23:14:15+00:00] DEBUG: Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
[2014-01-28T23:14:15+00:00] DEBUG: Content-Length: 31
[2014-01-28T23:14:15+00:00] DEBUG: POST environments/_default/cookbook_versions
— POST BODY —
{“run_list”:[“zero-test”]}
— END POST BODY —
[2014-01-28T23:14:15+00:00] DEBUG:
— RESPONSE (412) —
{
“error”: [
“No such cookbook: zero-test”
]
}
— END RESPONSE —
[2014-01-28T23:14:15+00:00] DEBUG: ---- HTTP Status and Header Data: ----
[2014-01-28T23:14:15+00:00] DEBUG: HTTP 1.1 412 Precondition Failed
[2014-01-28T23:14:15+00:00] DEBUG: content-type: application/json
[2014-01-28T23:14:15+00:00] DEBUG: server: chef-zero
[2014-01-28T23:14:15+00:00] DEBUG: connection: close
[2014-01-28T23:14:15+00:00] DEBUG: content-length: 59
[2014-01-28T23:14:15+00:00] DEBUG: ---- End HTTP Status/Header Data ----
[2014-01-28T23:14:15+00:00] INFO: HTTP Request Returned 412 Precondition Failed: No such cookbook: zero-test

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

Missing Cookbooks:

No such cookbook: zero-test

Last, here’s something that works 100%, except that it requires me to symlink
the cookbook I want to run from the dir site-cookbooks to cookbooks.

$ cd ~/dev/git/chef-repo/

cd cookbooks/; ln -s ../site-cookbooks/zero-test zero-test; cd .. rm -rf nodes
$ chef-client -l debug -z -o “recipe[zero-test]”

It works. The nodes dir is created, the node data created therein, and the
cookbook runs. Hrmpf?

Thanks in advance!
kallen


#2

Earlier today we released a new install.sh script with a few fixes.

  • support for -d option needed by vagrant-cachier
    (https://github.com/fgrehm/vagrant-cachier/issues/13)
  • the patch to add -d also appears to have fixed linux mint installs as
    a side effect (cleaner code is cleaner)
  • added a -P server option to install the OSS server instead of the
    chef-client, eg:

curl -L https://www.opscode.com/chef/install.sh | bash -s – -P server

that works on ubuntu and redhat/centos – fedora, oracle, amazon still
have issues with CHEF-3838

  • changed sles 10 and opensuse 11 to download the el5 binary which might
    fix them (i’d like to know if it does: CHEF-4892)
    https://tickets.opscode.com/browse/CHEF-4892
  • a few tweaks to error handling and suppressing stderr output