Chef Learnings 1.0 JRuby – the watershed for enterprise Ruby?
Jan 26

Today’s topic, Libraries and including them in multiple Cookbooks. Any custom library loaded into a single Cookbook is available to all Cookbooks within your Node. So for example, let’s say you have a custom function that operates on Data Bags (like I do), it is available to all recipes. For example, if you include in a library one of your base/default cookbooks (like IPTables), then any other recipe can access those methods. The trick is that in your first recipe where you include your custom library, you have monkey patched Chef to include it thereafter:

class Chef::Recipe
  include DataBagHelper
end

So nice, now I have my custom library available everywhere. This makes me think, why not just have a custom library cookbook, or make my custom libraries part of my base/default recipe included in ALL nodes? So now I have my own methods and functionality available everywhere.

Leave a Reply