A LWRP is a part of a cookbook that is used to extend the chef-client in a way that allows custom actions to be defined, and then used in recipes in much the same way as any platform resource. A LWRP has two principal components:
Once created, a LWRP becomes a Ruby class within the organization. During each chef-client run, the chef-client will read the lightweight resources from recipes and process them alongside all of the other resources. When it is time to configure the node, the chef-client will use the corresponding lightweight provider to determine the steps required to bring the system into the desired state.
Where the lightweight resource represents a piece of the system, its current state, and the action that is needed to move it to the desired state, a lightweight provider defines the steps that are required to bring that piece of the system from its current state to the desired state. A LWRP behaves similar to platform resources and providers:
Read more about how to build custom lightweight resources.
A lightweight resource is created by the action block of a lightweight provider. When the resource collection is compiled, a lightweight resource is inserted into the top-level resource collection after the point at which the lightweight provider is associated. For example, if a resource collection looks like:
top_level_resource_one lwrp_resource top_level_resource_two
then when lwrp_resource is executed, the resource collection will be modified as follows:
top_level_resource_one # already processed lwrp_resource # already processed embedded_resource_one # created by the lightweight provider embedded_resource_two # created by the lightweight provider top_level_resource_two
In this situation, embedded lightweight resources cannot notify the top-level resource because the top-level resource has finished processing. This has the same effect as if the top-level resource collection were invisible to the embedded lightweight resources.
To ensure that an embedded lightweight resource can notify the top-level resource add use_inline_resources to the top of the file that defines the lightweight provider that is associated with that lightweight resource. When use_inline_resources is added to the file, the code in the lightweight provider’s action block will execute as part of a self-contained chef-client run. If any embedded lightweight resources are updated, the top-level lightweight resource is marked as updated and notifications set for the top-level resource will be triggered normally.
Custom resources and providers can also be created using the LWRP DSL. Chef maintains a collection of cookbooks that define some common scenarios. Many of these cookbooks contain custom resources. To use these resources within recipes to increase automation opportunities the cookbook that defines these custom resources must also be uploaded to the server so that the custom resources are available to the chef-client during a chef-client run.
|apt||The apt cookbook is used to configure APT and APT services, for managing APT repositories and preferences.|
|aws||The aws cookbook is used to manage resources that are running in Amazon Web Services.|
|bluepill||The bluepill cookbook is used to install Blue Pill, and then use it to manage services.|
|chef_handler||The chef_handler cookbook is used to distribute and enable exception and report handlers.|
|daemontools||The daemontools cookbook is used to install and configure daemontools so that it can be used to manage UNIX services.|
|djbdns||The djbdns cookbook is used to install djbdns and use it to configure DNS services.|
|dmg||The dmg cookbook is used to create a DMG package for use with Mac OS X.|
|dynect||The dynect cookbook is used to manage DNS records using the DynECT REST API.|
|firewall||The firewall cookbook is used to manage firewalls and their associated firewall rulesets.|
|freebsd||The freebsd cookbook is used to manage port options for FreeBSD.|
|gunicorn||The gunicorn cookbook is used to install and configure Gunicorn.|
|homebrew||The homebrew cookbook is used to install and configure Homebrew for use as the package manager for Mac OS X.|
|iis||The iis cookbook is used to install and configure Internet Information Services (IIS).|
|maven||The maven cookbook is used to install and configure Apache Maven.|
|nagios||The nagios cookbook is used to install and configure Nagios.|
|pacman||The pacman cookbook is used to install the pacman package manager and configure groups.|
|php||The php cookbook is used to install and configure PHP and PHP modules.|
|powershell||The powershell cookbook is used to install Windows PowerShell.|
|python||The python cookbook is used to install Python, pip, and virtualenv.|
|rabbit mq||The rabbitmq cookbook is used to install and configure RabbitMQ.|
|riak||The riak cookbook is used to install and configure the Riak distributed data store.|
|samba||The samba cookbook is used to install and configure Samba.|
|sudo||The sudo cookbook is used to install sudo and configure /etc/sudoers.|
|supervisor||The supervisor cookbook is used to install Supervisor and use it to provide resources while configuring services.|
|transmission||The transmission cookbook is used to install and configure the Transmission BitTorrent client.|
|users||The users cookbook is used to create users based on a data bag search.|
|webpi||The webpi cookbook is used to run the Microsoft Web Platform Installer (WebPI).|
|windows||The windows cookbook is used to configure auto run, batch, reboot, enable built-in operating system packages, configure Microsoft Windows packages, reboot machines, and more.|
|yum||The yum cookbook is used to manage the contents of the yum.conf configuration file for global yum configurations and for individual yum repositories.|