How to add same cook book recipe in other recipe
include_recipe "localcookbook::test"
where i have included there test recipe variables are not passing
How to add same cook book recipe in other recipe
include_recipe "localcookbook::test"
where i have included there test recipe variables are not passing
Local variables are not visible across an include because that would make them not local variables. Or more generally because that isn't how Ruby works.
In order to achieve what you want you need to use cookbook's helpers and libraries. As a start you can check this resources for libraries https://blog.chef.io/2014/03/12/writing-libraries-in-chef-cookbooks/
This is basic examples with helpers.
In your cookbook folder you needs to create libraries/helpers.rb file
module MyCookbook
module Helpers
@@state_value ||= ''
def set_state_value(v)
@@state_value = v
@@state_value
end
def get_state_value
@@state_value
end
end
end
Chef::Recipe.send(:include, MyCookbook::Helpers)
Lets say that you have two recipes - A and B (executed sequently) in chef.
In A you put set_state_value("state value")
and in B get_state_value
and you have what you set from A recipe in B recipe.