Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chef - share libraries between cookbooks

Is it possible to reuse the code from a cookbook library in another cookbook provider/library?

cookbook1/libraries/lib.rb

    ...
    def very_useful_check
      true
    end
    ...

cookbook2/libraries(providers?)/foo.rb

...
myvar = very_useful_check
...

thanks

like image 627
John Stadt Avatar asked Oct 22 '22 08:10

John Stadt


1 Answers

It's possible by using Chef Libraries.

make sure the functions are defined in your namespace via ruby modules:

module Foo
  def very_useful_check
    true
  end
end

class Chef::Recipe::namespace
  include Foo
end

Then you can use it in any recipe like:

myvar = Foo.very_useful_check
like image 118
shawnzhu Avatar answered Oct 27 '22 07:10

shawnzhu