0
votes

Experts,

I am in a situation where I want to use a resource (file) provided by chef but I want to write my own provider for that I will pass with 'provider' attribute for 'file' resource.

I do not want to write an LWRP (resource and provider). I just want to use a resource that is there but the provider should be the one that I am defining.

How can I just write a provider and override the provider provided by chef for a resource? What are the classes that I need to use/inherit? Where do I put my class on chef-server?

1

1 Answers

0
votes

All Chef resources respond to a provider attribute in the resource declaration:

file '/path/to/file' do
  provider My::Custom::Provider
end

Note that this is the actual class, not a string or symbol. Alternatively, if you want the provider to be used on a specific platform, you can use Chef::Platform.set:

Chef::Platform.set(
  resource: :file,
  provider: My::Custom::Provider,
  platform: :windows,
)

Then use use the resource as normal, but Chef will "do the right thing" when encountering the given platform.