Book Image

Chef Infrastructure Automation Cookbook

By : Matthias Marschall
Book Image

Chef Infrastructure Automation Cookbook

By: Matthias Marschall

Overview of this book

Table of Contents (14 chapters)
Chef Infrastructure Automation Cookbook Second Edition
About the Author
About the Reviewers

Creating your own Lightweight Resource Providers (LWRP)

Chef offers the opportunity to extend the list of available resources by creating a custom Lightweight Resource Provider (LWRP). By creating your own custom resources, you can simplify writing cookbooks because your own custom resources enrich the Chef DSL and make your recipe code more expressive.

Many of the custom resources in Chef's community cookbooks (and elsewhere) are implemented as LWRPs. So, there are many working examples in the real world, such as iptables_rule, apt_repository, and many more.

In this section, we will create a very simple LWRP to demonstrate the basic mechanics.

Getting ready

Create a new cookbook named greeting and ensure that the run_list of your node includes greeting, as described in Creating and using cookbooks recipe of Chapter 1, Chef Infrastructure.

How to do it...

Let's see how to build a very simple LWRP to create a text file on your node:

  1. Create your custom resource in your greeting cookbook: