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?

Code Silverback
  • 3,204
  • 5
  • 32
  • 39

1 Answers1

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.

sethvargo
  • 26,739
  • 10
  • 86
  • 156
  • 1
    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. – Draco Ater Aug 26 '14 at 19:57
  • 7
    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. – Holger Just Aug 27 '14 at 17:10
  • 2
    @sethvargo You are one of the authors of Chef. At least you work there :) Whom else should we ask? – Draco Ater Aug 27 '14 at 18:13
  • 5
    What is the point of allowing multiple attribute files in a cookbook, if they are all loaded automatically? – Jan Hettich Feb 13 '15 at 00:28
  • 2
    @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. – George Reith Sep 25 '15 at 16:24