A lightweight resource and provider is a simple way to implement resource and provider functionality that is not already built-in to Chef. Once created, the lightweight resource and provider become a Ruby class within the Chef environment. A lightweight resource and provider require less coding and are ideal for implementing specific sets of desired functionality quickly.
| Topic | Description |
|---|---|
| File Locations | Lightweight resources and providers are loaded from files that are saved in cookbook sub-directories. |
| Compare Platform and Lightweight Resources | Lightweight resources are much less complicated than platform resources. |
| Example: Create a Lightweight Resource and Provider | Creating a lightweight resource involves a few steps, a few files, and a cookbook. |
| Lightweight Resources Reference | There are many lightweight resources that are found in cookbooks maintained by Opscode. |
A lightweight resource is a custom resource that creates an abstract approach for defining a set of actions and (for each action) a set of attributes and validation parameters. A lightweight resource relies on a lightweight provider to take the necessary steps to bring a piece of the system to a desired state.
All lightweight resources share the same set of common functionality:
| Topic | Description |
|---|---|
| Syntax | A lightweight resource is an abstract interface that specifies one (or more) actions that can be taken, one (or more) attributes, and then for each attribute a validation rule that defines how each attribute can be applied. |
| Actions | Use the :nothing action to do nothing. |
| Attributes | Attributes are available for timeouts, to set the current working directory, specify environment variables, groups, and users. |
| Conditional Executions | A conditional execution can be used to put additional guards around certain resources so that they are only run when the condition is met. |
| Inline Compile Mode | Execute a lightweight resource as part of a self-contained Chef run during resource compilation. |
| Notifications | Lightweight resources can notify each other to take certain actions. |
| Relative Paths | The environment home relative path can be set in a lightweight resource. |
A lightweight provider is a custom provider that is designed to take the steps that are required to bring a piece of the system into a specific state based on an action that is defined by a lightweight resource.
Note
Typically, using a lightweight provider is the best (and recommended) way of handling a resource that does not already exist. If using a lightweight provider is not an option, then creating a custom provider might be the best approach. Please use the Chef IRC channel to contact us and we will help you get started.
| Method | Description |
|---|---|
| Actions | Actions are defined as list of keywords in a resource. |
| Extend a Lightweight Provider | A lightweight provider can extend another provider class. |
| Use the Default Provider | If a lightweight resource is used in a recipe, and the provider attribute is omitted, Chef will look for a lightweight provider of the same name as the resource in the same cookbook by default. |