Chef Attributes: does file name matter?
Asked Answered
S

1

12

When I create attributes in my cookbook's attributes /attributes/default.rb things work fine.

If I add a recipe to my cookbook, say /recipes/dofubar.rb, I expect that attributes defined in /attributes/dofubar.rb to be loaded. They do not appear to be.

Is there a way to define one set of default attributes for one recipe and other sets for other recipes?

Southdown answered 26/8, 2014 at 16:1 Comment(0)
R
21

There is no correlation between attribute file names and recipes. All files in the attributes/ folder are loaded in order during the start of the Chef Client run. Even if you name an attribute.rb file the same as a recipe, Chef makes no correlation. All attribute files will be loaded each time.

Ratiocinate answered 26/8, 2014 at 17:27 Comment(5)
Why so? It seems logical to correlate attribute and recipe file name. And if one wants to load some other attribute file, then include_attribute is the way.Endocarditis
As a little note here: when loading the attribute files, the default.rb will always be loaded first. After that, all the other attribute files in the cookbook will be loaded in alphabetical order.Brezhnev
@Ratiocinate You are one of the authors of Chef. At least you work there :) Whom else should we ask?Endocarditis
What is the point of allowing multiple attribute files in a cookbook, if they are all loaded automatically?Sup
@JanHettich For organisational purposes... say I have a bunch of attributes specific to a single template. If I ever need to add, edit or delete them it becomes a lot easier if they grouped.Lien

© 2022 - 2024 — McMap. All rights reserved.