9

I wrote a small LWRP my app cookbook (trim_log), and it works. However, now I am trying to move this particular LWRP in to the commons cookbook so that my other cookbooks can also use it. The problem is that I cannot figure out how to load in the trim_log resource/provider in to any of the cookbooks, including my app cookbook.

├── app
│   ├── recipes
│       └── default.rb
├── commons
   ├── providers
   │   └── trim_log.rb
   └── resources
       └── trim_log.rb

I have defined the trim_log provider/resource in the commons cookbook. Now I wish to use this trim_log provider/resource in the app cookbook. How can I make it available there?

Mark Amery
  • 143,130
  • 81
  • 406
  • 459
Michael van Rooijen
  • 6,683
  • 5
  • 37
  • 33

1 Answers1

21

I believe you need to:

  • Declare in the app/metadata.rb that you depend on the commons cookbook.
  • Refer to the resource as commons_trim_log in app/recipes/default.rb.
Emil Sit
  • 22,894
  • 7
  • 53
  • 75
  • 2
    I didn't realize you had to specify the dependency of `commons` in the `app` cookbook's `metadata.rb`. That fixed it, thanks a lot! – Michael van Rooijen Jun 26 '13 at 21:15
  • 3
    If you are working with multiple cookbooks, you should check out [Berkshelf](http://berkshelf.com) and [Foodcritic](http://acrmp.github.io/foodcritic/), both of which will push you to write better `metadata.rb` files. – Emil Sit Jun 27 '13 at 02:44