|
As you work with Chef, it will be important to understand the path we take during execution of the Chef Client. ConvergenceWe call the process of running the Chef Client or Chef Solo and taking any needed actions on Resources "Convergence". In a nutshell, Convergence in systems automation speak means "bringing the system closer to correct with each action you take". Ideally, a single run of the Chef Client should always bring the system into the fully expected state - not just half-way. But if it doesn't work out, trying again should continue to bring the system closer to correct. |

Build, Register, and Authenticate the Node
Build the Node
The first thing Chef Client or Chef Solo do is build a new Node. The node is constructed from:
- Ohai - Ohai discovers the data about the Operating System first.
- The previous data for the node is fetched from the Chef Server (unless we are running under Chef Solo).
- Any JSON Attributes or Recipes are added.
- All the Ohai attributes are added.
Register for an OpenID
Once the Node is successfully created, we check that we have an OpenID Registration with the Chef Server. If we do not, we register for one now, including our validation_token. If the token matches the one on the Chef Server, then the node is Validated. Otherwise, an administrator must validate the node.
Authenticate
Now that we have confirmed our OpenID Registration, we Authenticate with our credentials.
Synchronize Cookbooks
Synchronize Libraries, Attributes, Definitions and Recipes
The Chef Client then queries the Chef Server for a list of all the Libraries, Attributes, Definitions and Recipes in all Cookbooks, and transfers them to the local file cache.
Compile Resource Collection
Now that we have all information from the Cookbooks, it's time to assemble the specific collection of resources needed to converge this node.
Load Libraries
We first load all the Libraries from every cookbook, making any language extensions or ruby classes available.
Load Attributes
Then we load all the Attribute files, which update the Node attributes and Recipes.
Load Definitions
Definitions must be loaded before Recipes, since they create new pseudo-Resources.
Load Recipes
At this point, the Recipes themselves are evaluated. We are not taking any action on the resources in the recipes at this stage - we are taking each evaluated resource and putting it in the Resource Collection. This is essentially an Array of each evaluated resource, along with some helpful functions. Plain Ruby code outside of resources is evaluated, however. If you would like Ruby code executed with other resources, use a Ruby Block Resource.
Configure Node
All that remains is executing the actions specified in our Resource Collection, but first...
Save Node
We need to save the state of the Node to the Chef Server. We do this so that an administrator can inspect what the full state of the Node was prior to Converging.
Converge
This is the actual convergence step. Each Resource in the Resource Collection is mapped to a [Provider], which then takes Action on it. The system is configured.
Save Node
Finally, we save the state of the node after it is converged, in case anything changed.