Best practice to declare an attribute that must be defined outside the cookbook?

What is the best way to declare an attribute in attributes/default.rb which is really expected to be defined at a higher level, say an environment or even a wrapper cookbook? I am reluctant to give it a default value, since it is too easy to forget to change it when a cookbook gets deployed. In the past we have used entries like “invalid” if it is a string, or an illegal number based on the context.

Should I just go all the way and use ‘nil’? As well as adding an explicit check in the recipe to look for the undefined value and log a descriptive message?


Stephen Corbesero, DevOps Engineer
Synchronoss - Mobile Innovation for a Connected World
Office: +1 484-821-4272
stephen.corbesero@synchronoss.com | www.synchronoss.com

That's exactly what I see most cookbooks doing - setting default attributes
to nil when they aren't supposed to be set to anything by default.

On Mon, Jun 9, 2014 at 6:35 AM, Stephen Corbesero <
Stephen.Corbesero@synchronoss.com> wrote:

What is the best way to declare an attribute in attributes/default.rb
which is really expected to be defined at a higher level, say an
environment or even a wrapper cookbook? I am reluctant to give it a
default value, since it is too easy to forget to change it when a cookbook
gets deployed. In the past we have used entries like “invalid” if it is a
string, or an illegal number based on the context.

Should I just go all the way and use ‘nil’? As well as adding an explicit
check in the recipe to look for the undefined value and log a descriptive
message?

--

Stephen Corbesero, DevOps Engineer

Synchronoss - Mobile Innovation for a Connected World

Office: +1 484-821-4272

stephen.corbesero@synchronoss.com | www.synchronoss.com

--
Best regards, Dmitriy V.

Yes, you can do that, and also combine it with an attribute validator
if you are concerned about making sure people set something somewhere
(and that the values are valid).

Example: GitHub - clintoncwolfe/chef-attribute-validator: A Rubygem implementing a rule engine for validating Chef node attributes.

  • Julian

On Mon, Jun 9, 2014 at 3:18 PM, DV vindimy@gmail.com wrote:

That's exactly what I see most cookbooks doing - setting default attributes
to nil when they aren't supposed to be set to anything by default.

On Mon, Jun 9, 2014 at 6:35 AM, Stephen Corbesero
Stephen.Corbesero@synchronoss.com wrote:

What is the best way to declare an attribute in attributes/default.rb
which is really expected to be defined at a higher level, say an environment
or even a wrapper cookbook? I am reluctant to give it a default value,
since it is too easy to forget to change it when a cookbook gets deployed.
In the past we have used entries like “invalid” if it is a string, or an
illegal number based on the context.

Should I just go all the way and use ‘nil’? As well as adding an explicit
check in the recipe to look for the undefined value and log a descriptive
message?

--

Stephen Corbesero, DevOps Engineer

Synchronoss - Mobile Innovation for a Connected World

Office: +1 484-821-4272

stephen.corbesero@synchronoss.com | www.synchronoss.com

--
Best regards, Dmitriy V.

--
[ Julian C. Dunn jdunn@aquezada.com * Sorry, I'm ]
[ WWW: Julian Dunn's Blog - Commentary on media, technology, and everything in between. * only Web 1.0 ]
[ gopher://sdf.org/1/users/keymaker/ * compliant! ]
[ PGP: 91B3 7A9D 683C 7C16 715F 442C 6065 D533 FDC2 05B9 ]