We actually have a bunch of approaches to address this problem.
However our favourite one is to use the “cutlery” helper cookbook 
and add snippets of code like
Check that the attribute node[“foo”][“bar”][“baz”][“myattr”] exists
and is a string and return it
myattr = RealityForge::AttributeTools.ensure_attribute(node,
Check that the attribute node[“foo”][“mOtherAttr”] exists and return it
myOtherAttr = RealityForge::AttributeTools.ensure_attribute(node,
We can also use the same approach to check contents of databags (pass
databag as first parameter). Of course
"RealityForge::AttributeTools.ensure_attribute" is really long so we
tend to shorten it to “ensure_attribute” via some ruby trickery.
On Thu, Oct 24, 2013 at 7:39 AM, Sölvi Páll Ásgeirsson firstname.lastname@example.org wrote:
For some cookbook attributes, you can not set a sensible default.
What i’m doing now is setting the attribute defaults to nil and creating a
_attribute_validation.rb recipe which is basically a sequence of:
Chef::Application.fatal! "foo[:attr] is unset. Override with sane values
This is repetitive and boring. Is there a smarter way of going about this
which I’m missing?
Is there a way to do this directly from the attributes/*.rb ?
Sölvi Páll Á