How to update nginx via Chef How to update nginx via Chef nginx nginx

How to update nginx via Chef


I'm running into this very same issue. Best I can tell, the root of the issue is the use of string concatenation in the attributes files in the nginx cookbook. If you look at attributes/source.rb you see the following

default['nginx']['source']['default_configure_flags'] = [  "--prefix=#{node['nginx']['source']['prefix']}",  "--conf-path=#{node['nginx']['dir']}/nginx.conf",  "--sbin-path=#{node['nginx']['source']['sbin_path']}"]

These are fine, reasonable defaults. And one would think that if one overrides one of the referenced attributes, node['nginx']['source']['prefix'], then the resulting default_configure_flags would reflect that change. However, that doesn't appear to be the case. It looks like attributes files are one of, if not the, first things loaded when running chef. So the values assigned to things like default_configure_flags are based on the defaults provided with the cookbook (i.e. the version string 1.2.6 which is set in attributes/default.rb).

Short of doing some serious cleanup work on the nginx cookbook itself, my best solution was to override the default_configure_flags attribute in my own attributes file (along with a number of others that seem like they should be fine, but cause the same issue, look at the rest of the attributes/source.rb for the reset). Unfortunately, I'm overriding it to the same thing as the default, it just get's evaluated later after the other values that it references are set to what I want.


This line:

[2013-07-15T18:52:03-04:00] INFO: Processing remote_file[http://nginx.org/download/nginx-1.2.6.tar.gz] action create (nginx::source line 56)

Points to line 56 of the source recipe on the nginx cookbook. There you can see that the URL for the source archive is set using this logic:

nginx_url = node['nginx']['source']['url'] || "http://nginx.org/download/nginx-#{node['nginx']['source']['version']}.tar.gz"

So I guess that node['nginx']['source']['url'] is pointing to version nginx version 1.6. It should be dependent on the node['nginx']['source']['version'] attribute as can be seen here, but maybe there's some attribute loading order at work here that's getting in the way.

Try setting node['nginx']['source']['url'] to http://nginx.org/download/nginx-1.4.1.tar.gz while keeping the source version also set to 1.4.1.

My guess is that you're downloading 1.2.6 while trying to extract 1.4.1, which is not there, so the bash script fails.