Chef-client not updating a cookbook from the server

chef

I have a chef cookbook (for apache2). It fails to work on one node. So I'm trying to tweak it and update it, but the node doesn't seem to download the new version. I have been able to upload everything to the chef server from my local machine with knife upload ., that succeeds, and prints out that it uploaded the apache2 cookbook bits that I changed.

When I manually run (as root) chef-client on the node, I can see it contacting the server, getting the run list, etc. However the recipe files in /var/cache/chef/cookbooks/apache2 are the old files. And the recipe fails (because it doesn't have the changes I made).

How do I get the chef client on the node to use the new updated version of the apache2 cookbook? Do I need to bump the version number in the cookbook (I haven't been doing this)?

chef-client -l debug output:

[2015-01-30T10:51:31+01:00] DEBUG: Synchronizing cookbook apache2
[2015-01-30T10:51:31+01:00] DEBUG: Not storing cookbooks/apache2/recipes/mod_ldap.rb, as the cache is up to date.
[2015-01-30T10:51:31+01:00] DEBUG: Not storing cookbooks/apache2/recipes/mod_xsendfile.rb, as the cache is up to date.
[2015-01-30T10:51:31+01:00] DEBUG: Not storing cookbooks/apache2/recipes/mod_auth_openid.rb, as the cache is up to date.
[2015-01-30T10:51:31+01:00] DEBUG: Not storing cookbooks/apache2/recipes/mod_setenvif.rb, as the cache is up to date.
[2015-01-30T10:51:31+01:00] DEBUG: Not storing cookbooks/apache2/recipes/mod_python.rb, as the cache is up to date.
[2015-01-30T10:51:31+01:00] DEBUG: Not storing cookbooks/apache2/recipes/mod_authz_host.rb, as the cache is up to date.
[2015-01-30T10:51:31+01:00] DEBUG: Not storing cookbooks/apache2/recipes/mod_proxy_ajp.rb, as the cache is up to date.
[2015-01-30T10:51:31+01:00] DEBUG: Not storing cookbooks/apache2/recipes/mod_expires.rb, as the cache is up to date.
(lots of this for all files)

I am new to chef, so I might have made a beginner mistake.

Best Answer

There's a couple of things I can think of that might help you out.

  1. Verify that the cookbook version you are uploading is the most recent version

    A common problem with cookbook versioning is that you may be modifying cookbook version 1.0.0 locally and uploading, but the Chef Server has cookbook version 1.0.1 already uploaded to it. In that case, Chef Clients will typically retrieve the latest version (unless told otherwise) and your changes will never sync to the local cache.

    You can see all current versions of the cookbook on Chef Server via: knife cookbook show apache2

    One solution to this is the one you mentioned - increase your version number beyond what exists on Chef Server , i.e. 1.0.2 and upload.

    Another method is to remove any other apache2 cookbooks from Chef Server, and re-upload the one you want. This doesn't need any version number updates, and the end result is that Chef Server would have a single apache2 cookbook.

  2. Validate that your changes are indeed making it to Chef Server

    Using knife cookbook show apache2 <cookbook version> recipes default.rb Replace version, path, and filename - for instance if you wanted to view a template named foo.erb: knife cookbook show apache2 0.1.0 templates foo.erb

    This command will request the file from the Chef Server and display the output in your terminal. This is a simple way to determine that the changes you made are being uploaded via knife cookbook upload.

Beyond these, if this doesn't help out, adding the details of knife version, chef-server version, chef-client version as well as a debug log from knife cookbook upload apache2 -VV would be helpful in debugging further.