Book Image

Mastering Chef

By : Mayank Joshi
Book Image

Mastering Chef

By: Mayank Joshi

Overview of this book

Table of Contents (20 chapters)
Mastering Chef
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
2
Knife and Its Associated Plugins
10
Data Bags and Templates
Index

Custom resources


There are two ways to define custom resources – via LWRPs (lightweight resource providers) or HWRPs (heavyweight resource providers). Before LWRPs were introduced, all extensions to Chef were written using Ruby, and these are referred to as HWRPs. While LWRPs are simple, a HWRP is extremely flexible. The HWRPs reside in the libraries folder of the cookbook repository. Chef tries to import anything residing there at runtime and is interpreted as code, rather than a Chef DSL. We'll mostly be concerned with LWRPs in this chapter.

A LWRP is meant to extend chef-client so that custom actions can be defined and eventually used in a recipe.

A LWRP has two main components. They are as follows:

  • A lightweight resource that defines a set of actions and attributes

  • A lightweight provider that tells the chef-client how to handle each action

One may use existing resources or custom Ruby code to build a new LWRP. Once a LWRP is ready, it's read every time during the chef-client run and processed...