You can use node.run_state[:foo] ||= "bar" style code blocks to do this.
i generally prefer to move this into a library, and if possible back it by
a separate singleton class, this is a common requirement, like if you are
using some data bag across recipes etc, this helps avoiding making multiple
chef server api call during a single chef run.
i have thought of raising an RFC for this, i.e. a global (chef-client),
locally cached version of data store, but the ordering bit (where you'll
define it, if recipe, how you ensure its executed in the beginning. should
we introduce some like initializers.. etc?)
On Tue, Apr 28, 2015 at 10:28 AM, Mathew Crane mathew.crane@gmail.com
wrote:
Scenario:
- Two custom variables are dynamically assigned based on
node.chef_environment via a targeted search and subsequent for-loop against
a max of 10 top-level data bag items.- Both variables are a DataBagItem.
- They are defined within any recipe that needs these values.
- Setting this in every recipe doesn't scale.
Is there a way to define these variables once in a separate,
single-purpose cookbook recipe, and have them reliably made available to
all recipes within the chef run?What is the best direction for this? Setting attributes via
attributes/default.rb or creating a custom library with a ruby block?Thanks!
-Mat