I'm having trouble with the nginx recipe from opscode. It seems like it never picks up on a variable I set in my attributes.
I have a "base" recipe, with an attributes/default.rb
file that looks like this:
default.nginx.install_method = 'source'
default.nginx.source.version = '1.5.3'
That base
recipe eventualy calls include_recipe "nginx::source"
But it fails, as shown here:
Resource Declaration:
---------------------
# In /tmp/vagrant-chef-1/chef-solo-1/cookbooks/nginx/recipes/source.rb
84: bash "compile_nginx_source" do
85: cwd ::File.dirname(src_filepath)
86: code <<-EOH
87: tar zxf #{::File.basename(src_filepath)} -C #{::File.dirname(src_filepath)} &&
88: cd nginx-#{node['nginx']['source']['version']} &&
89: ./configure #{node.run_state['nginx_configure_flags'].join(" ")} &&
90: make && make install
91: EOH
92:
93: not_if do
94: nginx_force_recompile == false &&
95: node.automatic_attrs['nginx'] &&
96: node.automatic_attrs['nginx']['version'] == node['nginx']['source']['version'] &&
97: node.automatic_attrs['nginx']['configure_arguments'].sort == configure_flags.sort
98: end
99:
100: notifies :restart, "service[nginx]"
101: end
102:
Compiled Resource:
------------------
# Declared in /tmp/vagrant-chef-1/chef-solo-1/cookbooks/nginx/recipes/source.rb:84:in `from_file'
bash("compile_nginx_source") do
action "run"
retries 0
retry_delay 2
command "\"bash\" \"/tmp/chef-script20130731-14469-f1tw0d\""
backup 5
cwd "/var/chef/cache"
returns 0
code " tar zxf nginx-1.5.3.tar.gz -C /var/chef/cache &&\n cd nginx-1.5.3 &&\n ./configure --prefix=/opt/nginx-1.2.6 --conf-path=/etc/nginx/nginx.conf --sbin-path=/opt/ngi
nx-1.2.6/sbin/nginx --with-http_ssl_module --with-http_gzip_static_module &&\n make && make install\n"
interpreter "bash"
cookbook_name :nginx
recipe_name "source"
not_if { #code block }
end
which fails with cd: nginx-1.5.3: No such file or directory
Some weirdness:
- the
--prefix
is nginx-1.2.6, which does not make any sense, since the prefix is built from the version here - the nginx download url seems to fail too. It's built here
So, basically it seems I'm maybe setting my attributes incorrectly?
You need to override additional variables:
prefix
,url
,sbin_path
, anddefault_configure_flags
:This is because these variables embed other variables, and they are set using values that have not yet been overriden by your values.
By specifying these additional variables in your wrapper cookbook, you ensure they are using all the updated values you expect.
Also, because the
default
values are already set in the nginx cookbook, it's better to use something likeset
(an alias fornormal
) as that more accurately describes what you are doing and has a higher attribute precedence.