|
Libraries are defined in your_cookbook/libraries/library_name.rb.
Here's a simple example, showing how you'd use module defined in a Library in your recipe: your_cookbook/libraries/your_example_library.rb your_cookbook/recipes/default.rb Basic LibrariesLets say you have a customer record you are storing in an attribute file, that looks like this: A customer attribute file In a recipe, you could say: Simple recipe But that feels verbose, and you are going to do it all the time. You would rather say: Advanced recipe You could achieve that with a simple library, like this: Library to extend Chef::Recipe Lets say you wanted some code to easily loop over every customer, like this: Loop over customers You could have a library like this: Loop over customers Advanced Library UsageYou can also use Libraries to connect up to databases, talk to LDAP, or do anything else you can do with Ruby.. which is basically anything. Here is an example of connecting to a database and returning a list of customer Virtual Hosts. Virtual Hosts from a Database
Using ISP.vhosts in a Recipe
|
|
|



1 Comment
comments.show.hideSep 16, 2010
Dave
NB Subdirectories in the libraries folder are not synced with clients http://tickets.opscode.com/browse/CHEF-672