Reputation: 2288
the gist of my problem is located here:
https://gist.github.com/tsabat/a8f27ae6ac7d1fd3b6f7
The high-level problem is that chef-solo does not seem to pick up on attributes I set in my attriutes/default.rb
file for a recipe.
I recently switched to chef 11 from 10 and I think that some breaking changes have me over a barrel.
Please help.
Upvotes: 4
Views: 1176
Reputation: 933
You need to override additional variables: prefix
, url
, sbin_path
and default_configure_flags
:
set['nginx']['version'] = "1.5.3"
set['nginx']['source']['version'] = "1.5.3"
# The Chef checksum of a binary is determined by: shasum -a 256 FILE_NAME
set['nginx']['source']['checksum'] = "edcdf2030750b4eb1ba8cd79365c16a3e33e6136b7fdd8a1a7b4082397f4e92b"
set['nginx']['source']['prefix'] = "/opt/nginx-#{node['nginx']['source']['version']}"
set['nginx']['source']['url'] = "http://nginx.org/download/nginx-#{node['nginx']['source']['version']}.tar.gz"
set['nginx']['source']['sbin_path'] = "#{node['nginx']['source']['prefix']}/sbin/nginx"
set['nginx']['source']['default_configure_flags'] = [
"--prefix=#{node['nginx']['source']['prefix']}",
"--conf-path=#{node['nginx']['dir']}/nginx.conf",
"--sbin-path=#{node['nginx']['source']['sbin_path']}"
]
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 like set
(an alias for normal
) as that more accurately describes what you are doing and has a higher attribute precedence.
Upvotes: 3
Reputation: 2288
So, I don't have an answer to why chef treats variables differently in recipes, but here is my fix.
Some change in the way attributes are picked up from a cookbook has me vexed. Since I was using Chef Solo and it not supports roles, I just created a role, overrode the attributes there, and then called my base cookbook.
This model works more closely with how I conceptualize Chef when I'm working on the server, so it is a valid solution for me. I did the following:
Create a role called Base
name "base"
description "The base role"
run_list "recipe[base]"
override_attributes "nginx" =>
{
'install_method' => 'source',
'source' => {'version' => '1.5.3'}
}
Add the role to the runlist via the Vagrantfile
config.vm.provision "chef_solo" do |chef|
chef.cookbooks_path = "vendor/cookbooks"
chef.roles_path = "roles"
chef.data_bags_path = "data_bags"
chef.add_role "base"
end
Upvotes: 0
Reputation: 7585
Replied in your gist.
You need another default attribute "default['nginx']['version'] = 1.5.3" or it will override your compile flag --prefix
.
Upvotes: 0