Questions tagged [lwrp]

An 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.

An 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:

  • A lightweight resource that defines a set of actions and attributes
  • A lightweight provider that tells the chef-client how to handle each action, what to do if certain conditions are met, and so on In addition, most lightweight providers are built using platform resources and some lightweight providers are built using custom Ruby code

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:

  • A lightweight resource is a key part of a recipe
  • A lightweight resource defines the actions that can be taken
  • During a chef-client run, each lightweight resource is identified, and then associated with a lightweight provider
  • A lightweight provider does the work to complete the action requested by the lightweight resource

You can read more about how to build custom lightweight resources on the Chef docs.

73 questions
18
votes
2 answers

chef only_if attribute equals true

Problem: I have a chef statement that should only run if the attribute is "true". But it runs every time. Expected Behavior: When default[:QuickBase_Legacy_Stack][:dotNetFx4_Install] = "false" dotnet4 should not be installed. Actual Behavior: No…
tbenz9
  • 446
  • 2
  • 5
  • 18
9
votes
1 answer

Including a Chef LWRP from another cookbook

I wrote a small LWRP my app cookbook (trim_log), and it works. However, now I am trying to move this particular LWRP in to the commons cookbook so that my other cookbooks can also use it. The problem is that I cannot figure out how to load in the…
Michael van Rooijen
  • 6,683
  • 5
  • 37
  • 33
5
votes
2 answers

How to use library module in Cookbook recipes

In a cookbook I have a library(client_helper.rb). A module is defined inside it. Module name is Client_helper. Here is the module code. module Client_helper # This module contains helper methods def network_zone Chef::Log.debug('network…
Biswajit Das
  • 644
  • 7
  • 26
5
votes
3 answers

Using File::read in a provider's default.rb in Chef

I am trying to create an LWRP that will call the resource that is defined within itself. My cookbook's structure is as follows: In the machine cookbook's provider, I have a code snippet as follows: require 'chef/provisioning' # driver for creating…
streetsoldier
  • 1,259
  • 1
  • 14
  • 32
5
votes
2 answers

How can a chef LW resource attribute default value refer to another attribute?

I'm trying to set the default value of one resource attribute to the value of another attribute. I'm defining a resource with the following definitions in it for a tomcat cookbook I'm building. I want to have "name" and "service_name" attributes…
Rich Mills
  • 99
  • 1
  • 6
4
votes
1 answer

Why does the LWRP custom definition gives me undefined method for nil:NilClass

I have problem with my custom definition of this LWRP. resources : user_postgresql. actions :create, :alter default_action :create attribute :username, :kind_of => String attribute :password, :kind_of => String attribute :database_name, :kind_of…
Robert
  • 10,403
  • 14
  • 67
  • 117
3
votes
3 answers

Double-sided shader with shader-graph

I'm a complete beginner when it comes to shaders, I'm building a project and I need to use Shader Graph in it. I would like to know if it is possible to render two different things on each side of a face, for example in the normal side render the…
Renan Klehm
  • 158
  • 1
  • 1
  • 9
3
votes
2 answers

Require a custom LWRP

I am stuck trying to create my first lwrp I have created a very basic resource + provider at: resources/rack_site.rb providers/rack_site.rb I've been trying to test the 'rack_site' resource within a recipe of the same cookbook, but it fails with an…
SystematicFrank
  • 16,555
  • 7
  • 56
  • 102
3
votes
1 answer

chef cookbook lwrp, easiest way to use new_resource.updated_by_last_action(true)

I'm writing a LWRP for chef 10. And when that resource is run in other recipes it should be marked as "updated_by_last_action" if something has changed. But if nothing has changed. updated_by_last_action should be false. So as example I have chef…
Raboo
  • 145
  • 1
  • 11
3
votes
3 answers

How to I get a chef custom lwrp to implement notifies and not_if?

I write a custom Lightweight resource. But the notifies and only_if is not recognized. Anyone else get this working? I use these in opsworks supplies resources. So I know I am using them correctly. Unfortunately proprietary code, so I can't post…
mpechner
  • 251
  • 3
  • 12
3
votes
1 answer

Using python_application Chef cookbook

I'm trying to use the django resource provided by the application_python cookbook: https://github.com/opscode-cookbooks/application_python If a follow the example provided…
2
votes
1 answer

Using directory resource inside Chef Provider LWRP

I'm trying to use directory resource under Chef LWRP, but unable to access the attribute inside the resource block, is there a way to do it. Or am I totally wrong and need different approach to achieve…
Shan
  • 2,141
  • 2
  • 17
  • 32
2
votes
1 answer

What are attribute methods of a Chef LWRP and what can I pass them?

I have the following attribute in a chef resource: attribute :attribName, kind_of: String, name_attribute: true, default: 'big string sldkjslkdflksdksdlkff' I want to break this up so it looks nice, so I did this: attribute [ :attribName, …
red888
  • 27,709
  • 55
  • 204
  • 392
2
votes
2 answers

Chef - Call action from other action in LWRP

I am defining a provider as below: action :start do ... end action :stop do ... end action :restart do ... end Now instead of rewriting the implementation of stop and start in restart, I would like to call action :stop and then action :start…
JahMyst
  • 1,616
  • 3
  • 20
  • 39
2
votes
1 answer

Chef, Apache2 cookbook ressource fails to find service[apache2] when called from a custom resource

In my custom chef cookbook (located at https://github.com/sanguis/chef-omeka/tree/lwrp). I am calling the Apache2 resource web_app from inside a custom resource (LWRP) that is being called from the custom solo.rb recipe. include_recipe 'apache2'…
Josh Beauregard
  • 2,498
  • 2
  • 20
  • 37
1
2 3 4 5