Nginx chef recipe doesn't pick my attributes

the essence of my problem is here:

https://gist.github.com/tsabat/a8f27ae6ac7d1fd3b6f7

The high level problem is that chef-solo does not seem to pick up the attributes set in my attriutes/default.rb file for the recipe.

I recently switched to a chef 11 out of 10, and I think some violations are changing per barrel.

Please, help.

+4
source share
3 answers

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 insert other variables, and they are set using values ​​that have not yet been overridden by your values.

By specifying these additional variables in your wrapper cookbook, you will ensure that they use all the updated values ​​that you expect.

In addition, since default values ​​are already set in the nginx cookbook, it is better to use something like set (an alias for normal ), since it more accurately describes what you are doing and has a higher attribute priority .

+3
source

Answers your question.

Do you need another default attribute "default ['nginx'] ['version'] = 1.5.3" or it will override the compilation flag --prefix .

0
source

So, I have no answer to the question why the chef treats the variables differently in the recipes, but here is my fix.

Some change in the way we get attributes from a cookbook annoyed me. Since I used Chef Solo and did not support the roles, I simply created the role, redefined the attributes there, and then named my main cookbook.

This model is more closely related to how I conceptualize the chef when I work on the server, so for me this is a valid solution. I have done 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 Role to Execution List via 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 
0
source

Source: https://habr.com/ru/post/1494601/


All Articles