AWS Opsworks: chef version 11.10, version Berkshelf 3.2.0.
I can't figure out how to use the helper library from cookbook A in ruby_block in cookbook B.
I found a post discussing how to include a method in ruby_block and also discussing how to share cookbook libraries, but I can't get both to work at the same time.
cookbookA / libraries / helpers.rb
module libraryA module Helpers def log(output) Chef::Log.info("
cookbookB / metadata.rb
depends 'cookbookA'
The following setup.rb works.
cookbookB / Recipes / setup.rb
::Chef::Recipe.send(:include, libraryA::Helpers) log("this is a log")
However, when I use the log function in the ruby ββblock, it fails. The following setup.rb does not work:
cookbookB / Recipes / setup.rb
::Chef::Recipe.send(:include, libraryA::Helpers) ruby_block "logging-function" do block do log("this is a log") end end
PS: I also tried using ::Chef::Resource.send(:include, libraryA::Helpers)
Updated code block:
::Chef::Recipe.send(:include, libraryA::Helpers) ruby_block "logging-test" do block do ::Chef::Recipe.send(:include, libraryA::Helpers) ::libraryA::Helpers.ttlog("message") end end
Received error: NoMethodError - undefined ttlog method for library A :: Helpers: Module
Updated Helpers
cookbookA / libraries / helpers.rb
def log(output) Chef::Log.info("#{cookbook_name}:#{recipe_name}: #output}") end
PS: Removed module structure