John Stadt
John Stadt

Reputation: 510

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

Upvotes: 5

Views: 1660

Answers (1)

shawnzhu
shawnzhu

Reputation: 7585

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

Upvotes: 3

Related Questions