Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overriding Chef default attributes and dependant attributes

Tags:

chef-infra

I can override default attributes in my recipes\roles but I am unable to get any other attributes that are dependant on that attribute to also update.

as an example, for the phantomjs cookbook I want to install 1.9.7 rather than the default 1.9.2. (I know this change has now been committed to the cookbook repo)

I can override the version with:

node.set['phantomjs']['version'] = "1.9.7"

but in the phantomjs default attributes there is a dependant attribute that uses this with string substitution to generate the base url for the download:

default['phantomjs']['basename'] = "phantomjs-#{node['phantomjs']['version']}-linux-#{node['kernel']['machine']}"

Is there a way to set the version attribute so that the change is performed before these dependant attributes are evaluated? Or a way to force a re-evaluation?

This has been a problem I have hit before and in the past I just override everything that is dependant .. but this is not a great approach going forward.

I am using the latest chef (just tested with 11.8.2 under vagrant but latest chef 11.10.4 elsewhere) and using both chef-solo and the chef server.

Thanks.

like image 674
BlueSkies Avatar asked Nov 11 '22 12:11

BlueSkies


1 Answers

You need to move your own cookbook (that override this attribute) upper in run list. String interpolation (foo-"#{whatever}") executed in compile time (while loading attribute files) and chef-client loads them in order of run list.

Or you have an option to override all dependent attributes manually, but this is road to hell.

like image 172
Gleb M Borisov Avatar answered Dec 06 '22 09:12

Gleb M Borisov