|
Providers take a resource, compare that resource to the current state of the part of the system it is managing, and then takes the Action specified in the resource. They are the way that Chef supports multiple platforms with a single Resource. What providers are available?The real question you should be asking is "What providers are available for a given Resource". You can find that answer by looking at the Resources page, in the Providers section for that resource type. |
How does Chef know which Provider to use?
Chef maps Providers to Platforms (and Platform Versions) via Chef::Platform. In this class you will find a class instance variable @platforms, which consists of a Hash of various Platforms and Versions. We look up the resource type in this hash according to your Nodes platform and platform_version Attributes (which are provided by Ohai).
How do Providers... Provide?
We did our best to keep adding new Providers to Chef as simple as possible. (For example, Adam wrote all the code for the http_request resource, including the provider and tests, in about 20 minutes, start to finish.)
- For each resource, we look up the proper provider
- We build a new instance of that provider
- We call load_current_resource, which uses the @new_resource as a template to look up the current state of the resource under management.
- We then call the action_ method for the action provided.
- Ensure we mark the resource as updated if any changes happened.
For example, given a resource such as:
We would:
- Look up the provider for a directory resource, which happens to be Chef::Provider::Directory
- Call load_current_resource, which creates a new directory["/tmp/monkey"] resource, based on the directories current state (which goes in @current_resource).
- Call action_create, which is responsible making sure the directory exists, and that it's attributes are correct.
- If we changed the directory in any way, we mark the resource as updated.
That's it!
I want to write a new Provider!
Awesome. We will help you out as much as we can. Go read the instructions for how to contribute to an Opscode project, hop on the Chef IRC channel, and get started.