This is awesome, looking forward to it!
Hope that cookbook authors would adopt the new "attribute style" rather than keeping the Chef 10.x "cookbook style" which is much less cleaner and intentional imho.
Cheers, Torben
Ohai Chefs,We recently merged some additional changes to attributes behavior forChef 11 that I'd like to make you aware of.## TLDR* Attributes from roles and environments are available when attributefiles are evaluated.* Chef::Node now includes platform introspection methods, so you can use`plaform?()` and friends in attributes files.* Default and Override attributes from cookbooks, roles, andenvironments are stored separately during the Chef run.* As a consequence of the above, setting a default or override attributein a recipe will no longer overwrite a value set by a role orenvironment.* CHEF-2936 http://tickets.opscode.com/browse/CHEF-2936## Accessing Role and Environment Attributes in Attributes FilesIn Chef 10.x and previous, you cannot set attribute values that dependon other attributes in attributes files, because you do not have accessto attributes from roles. For example, suppose you want to configure thedatabase for your app. You'd expect code like this to work (in anattributes file):node.default[:app][:name] = "my_app"node.default[:app][:env] = "development"node.default[:app][:database] ="#{node.app.name}_#{node.app.env}"However, this will not work if you intend to set `node[:app][:name]` or`node[:app][:env]` via roles or environments, because Chef will not haveseen those attributes when evaluating the attributes files.In Chef 11, role and environment attributes are applied when therun_list is expanded, so the above code will work the way you want itto.## Setting Platform-Specific Attributes in Attributes FilesIn Chef 10.x and previous, the utility methods for making choices basedon a node's platform or platform_family are available in recipes, butnot in attributes files. Some users have expressed a desire to be ableto set attributes based on platform in their attributes files. In Chef11, these methods are now available on node objects, so you can use themin attributes files. E.g.,:if platform?(:debian, :ubuntu)default[:foo] = "debian value"elsif platform?(:centos, :rhel)default[:foo] = "rhel value"elsedefault[:foo] = "generic value"end## Cookbook StyleTogether, these changes mean you can move attributes computations out ofrecipes and into attributes files. I personally think this style will bemuch better than what you must do currently, but we (Opscode) haven'tmade any official recommendation on this question yet. Do keep in mindthat any cookbook written using these features won't be usable on Chef10.x systems if you intend to make your cookbook public.If you wish to write your cookbooks with computed attributes inattributes files, don't forget to use `include_attribute()` to enforcethe desired attribute file load order.## Breaking ChangesThe implementation change that makes these features possible is apotentially breaking change.During a Chef run, default and override attributes from cookbooks,roles, and environments are now stored separately. In the followingcases, you may get a different result when computing the value of anattribute:### Attributes Files and Recipes Have the Same PrecedenceIn Chef 10.x and previous, setting a default attribute value in a recipewould overwrite a value set by a role or environment. In Chef 11, valuesset from a cookbook are stored separately, so the value set by the roleor environment will not be overwritten.Consider a role like this:default_attributes "app_name" => "from-role"And a recipe file like this:node.default["app_name"] = "from-recipe"In Chef 10.x and lower, the value of `node["app_name"]` will be"from-recipe". In Chef 11, the value will be "from-role"### Role and Environment Attributes are Visible to Attributes FilesIf, for some reason, you have been depending on attributes from rolesand environments not being visible during attribute file evaluation, youwill need to adjust your cookbooks or roles for this change.### What to Look For
Unlike the other changes to attributes in Chef 11, this one is abehavior change, meaning that valid usage can lead to different resultsin Chef 11 compared to Chef 10. I expect the vast majority of users willnot be affected, since it's unlikely you were depending on the oldbehavior intentionally.To see if you're affected, you'll need to take a look at your cookbooksand roles and look for attribute conflicts.One strategy is to inspect your recipes to see if you're settingdefaults:find . -name recipes -exec grep -n 'node.default' -r {} \;...and compare with your roles to see if there's a conflict.Another option is to use why-run mode and inspect the output for anyunexpected configuration changes.--Daniel DeLeo
Archive powered by MHonArc 2.6.16.