I have situation in my cookbook where i extract some values form data_bags and put them onto local variables on recipes after some manipulation of them. I am running on to a situation where i need to repeat this logic across many cookbooks as i see that when i do it in “default.rb” and then use them in include_recipe’s I see chef complaining that the variable is undefined, am not sure why so ideally when if I understand correctly all the recipes are compiled on to a single class by chef during converge so conceptually they should be visible.
Is there a way how i can share the variables declared in a recipe?
instance variables are shared across recipes, as each of the recipe is a
separate object. you can use node.run_state as small cross recipe storage
place. careful with this approach though, it might break why_run mode,
you can also use a dedicated module which exposes some common storage
place, as well as wraps reusable code, i prefer that, as its clean and i
can change the shared storage logic transparently,
regards
ranjib
I have situation in my cookbook where i extract some values form data_bags
and put them onto local variables on recipes after some manipulation of
them. I am running on to a situation where i need to repeat this logic
across many cookbooks as i see that when i do it in “default.rb” and then
use them in include_recipe’s I see chef complaining that the variable is
undefined, am not sure why so ideally when if I understand correctly all
the recipes are compiled on to a single class by chef during converge so
conceptually they should be visible.
Is there a way how i can share the variables declared in a recipe?
I have situation in my cookbook where i extract some values form data_bags and put them onto local variables on recipes after some manipulation of them. I am running on to a situation where i need to repeat this logic across many cookbooks as i see that when i do it in “default.rb” and then use them in include_recipe’s I see chef complaining that the variable is undefined, am not sure why so ideally when if I understand correctly all the recipes are compiled on to a single class by chef during converge so conceptually they should be visible.
Is there a way how i can share the variables declared in a recipe?