9

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.

Amandasaurus
  • 31,471
  • 65
  • 192
  • 253
  • Go to chef-server web interface and check, if the changes in the cookbook are there. – Draco Ater Jan 30 '15 at 15:59
  • 1
    Make sure you ran `knife cookbook upload `. If that doesn't solve it, try bumping the version and then running `knife cookbook list ` to make sure you are really uploading it properly. Alternately, run `knife cookbook download` (in another directory) to pull down what the server thinks is the right code. – Tejay Cardon Jan 31 '15 at 15:18

3 Answers3

6

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.

Mike Fiedler
  • 2,162
  • 1
  • 17
  • 34
  • 1
    Thank you so much for this answer... it led me to see that we had cookbook constraints in our production environment, not in our environments/production.rb but set by berkshelf! I didn't even know it could do that. Anyway, after re-uploading our production.rb environment, a new chef run picked up our latest app cookbook. – Colin Curtin Oct 08 '15 at 21:19
2

First debug all version of cookbooks on server and then check which version of cookbook the client is downloading. if it is old, just check if the server has an updated version. if it is also yes, Please go to chef server UI and check for env. you might have setup an enviornment in which cookbooks constraint are specified. Please update the version over there and it will start working again.

zedfauji
  • 21
  • 1
1

Another cause of this can be that not all the cookbook's dependencies are present on the chef-server. I ran into this just now, and the new version of my cookbook was showing up in knife cookbooks list but my client wasn't using the new version. After some debugging, I discovered that Berkshelf, nor knife had uploaded the new dependency for my cookbook. After I uploaded that, the client started using the newer version.

Michael Grubb
  • 13
  • 1
  • 3