Why defining Chef Attribute guidelines?
- Readability; easily identify the right attribute or recipe file, find the right default property value and understand how to override it
- Extensibility; easily override/overwrite attibute values from Chef JSON attributes, Chef wrapping cookbook defaults and recipes (see "Wrapping cookbook extensibility issues" below)
- Simplicity; Chef has many ways to define attributes, so it must be clear how to interact with chef-alfresco
Guidelines:
- Use
attributes/*.rb
for static attribute value definitions - Use
recipes/_*-attributes.rb
for derived attribute value definitions (or static ones that whose default values are not conditional) - Use
attributes/_common-attributes.rb
to define derived attributes that are needed also by other_*-attributes.rb
files - Never setup a node.default twice from different recipes
- Avoid using node.set and node.override within chef-alfresco
- Don't define `default['something'] = "#{node['something_else']}/more" (or similar, unless Ohai-based) in
attributes/*.rb
Imagine that you want to write your own-chef-alfresco
cookbook that wraps chef-alfresco
features, overriding some derived attributes, such as
node.set['alfresco']['properties']['dir.root.contentstore'] = #{node['alfresco']['properties']['dir.root']}/myowncontentstore`
Below the steps to perform:
- Identify which
_*-attributes.rb
file in chef-alfresco definesnode['alfresco']['properties']['dir.root']
, which isalfresco::_common-attributes.rb
- Create a Chef recipe that includes the recipe found in step #1 (i.e
recipes/default.rb
) - Set the attribute values (using node.default, node.set or node.override, depending on
alfresco::_common-attributes.rb
logic) that you want to define/overwrite - Call chef-alfresco default recipe
Here's the Chef code of recipes/default.rb
include_recipe "alfresco::_common-attributes.rb"
node.default['alfresco']['proprties']['dir.root.contentstore'] = #{node['alfresco']['proprties']['dir.root']}/myowncontentstore`
include_recipe "alfresco::default"
It is very important to note that not all chef-alfresco default attributes cannot be overridden by the default attributes of a wrapping cookbook(!)
Imagine the requirements described above; you could define attributes/default.rb
as follows:
default['alfresco']['properties']['dir.root.contentstore'] = "#{node['alfresco']['properties']['dir.root']}/myowncontentstore"
This code won't work, for 2 reasons:
- The default attribute value declaration (of
default['alfresco']['properties']['dir.root.contentstore']
) would be overridden byalfresco::_common-attributes.rb
- The attribute value of
node['alfresco']['properties']['dir.root']
is not set yet; onlyattributes/*.rb
attributes can be used here