Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
A node's attributes are certain information about it. Chef Infra Client uses attributes to have a proper understanding of:
The node's current status.
What the node was like at the last of the previous Chef Infra Client run.
What the node should be like at the last of the current Chef Infra Client run.
Attributes in Chef Infra are defined as :
Nodes that are saved on Chef infra
On the command line, attributes are supplied using JSON.
Cookbooks (in the form of attribute files and/or recipes).
Policy files.
Ohai
Ohai is a program that collects system configuration data. It feeds it to Chef Infra Client for usage in cookbooks. Ohai is executed at the start of every Chef Infra run to determine the system state. Ohai accumulates attributes known as automated attributes. These properties are used by Chef Infra Client to verify that nodes are in the desired state after each configuration run.
Attribute Arrays
Typically, attributes in Chef Infra are defined in cookbooks, recipes, roles, and settings. These properties are rolled up to the node level during a Chef Infra Client run.
A recipe can use a multi-level hash or array to store attribute values. For example, a group of web server properties could be:
But what if no two web servers are the same? What if some web servers demanded that a single attribute have a different value? You may save these settings in two places, one as the previous example and the other like this.
role 1 [ '1', '2' ]
+
role 2 [ '3' ]
=
[ '1', '2', '3' ]
Attribute Persistence
Except for regular Attributes in Chef Infra, all attributes are reset at the start of a Chef Infra Client run. Chef-client -j attributes set with a JSON file take precedence and are persisted between chef Infra Client operations.
Chef Infra Client rebuilds these attributes using Ohai. Ohai is a tool that collects system configuration data and feeds it to Chef Infra Client for usage in cookbooks. Ohai's automated attributes were collected at the beginning of the Chef Infra Client run. It is followed by default and overrides attributes supplied in cookbooks, roles, environments, and policy files.
According to attribute precedence, all attributes are mixed and assigned to the node. The attributes applied to the node are saved to the Chef Infra Server as part of the node object at the end of each Chef Infra Client run.
Limiting Attribute Persistence
Some businesses find it helpful to reduce the disc and CPU(central processing unit) resources. At the same time, processing useless attributes by controlling the attribute data stored in the Chef Infra Server.
For example, your company may find the Ohai Package plugin data. That is beneficial when building cookbooks. But you don't see the need to save 100k of package information for each Chef Infra Client run.
Limiting the data saved to the Chef Infra Server will still be available on the node within cookbooks. Still, it will not be stored in the Chef Infra Server, where it can be found in searches.
Attribute Blocklist
In the client.rb file attributes that a node should not save, can be blocked. The block list is a hash of keys that describes which attributes should be removed.
Attributes are blocklisted according to attribute type, with each attribute type blocklisted separately. Each attribute type—automatic, default, regular, and override—can define blocklists in the client.rb file.
Blocklisting Ohai Attributes
Use blocked Ohai(automatic) attributes. To prevent attributes from being populated by Ohai's system information collection.
Ohai collects many attributes that can take up significant storage space on the Chef Infra Server.
Many of these traits may be incredibly valuable. While others may be blocked without affecting the data available.
Normal, default and override properties are often far more significant in recipes.
Attribute Precedence
In both the default and override, the attribute precedence order for the sources "roles" and "environments" is reversed. The environment comes first, followed by the role. The overriding order is a role, followed by the environment.
Using the role override first allows you to use the same role in many situations. You can define a subset of these with context-specific parameters by applying the environment override on top of the role override.
Chef Infra Client uses the following properties in the next order:
Client
Function
default
Cookbook attribute fileRecipeEnvironmentRole
force_default
Cookbook attribute file recipe
normal
Chef-client -jCookbook attribute file recipe is used to pass a JSON file.
override
Cookbook attribute fileRecipeRoleEnvironment
force_override
Cookbook attribute file recipe
automatic
Ohai identified at the start of a Chef Infra Client Run
Attribute Sources
Chef Infra Client examines characteristics in order. They are defined in the run-list, along with any cookbook-dependent properties.
Many properties for policy files, environments, roles, and cookbooks are kept in the chef-repo (attribute files and recipes).
Ohai captures several attributes on each node at the start of each Chef Infra Client operation.
The properties stored in the chef-repo are periodically uploaded from the workstation to the Chef Infra Server.
The Chef Infra Client will retrieve the node object from the Chef Infra Server and reset all attributes except normal. The node object will contain the attribute data from the previous Chef Infra Client run, including any attributes set with the -j option using JSON files.
Chef Infra Client will (if necessary) update the cookbooks on the node, which will update the attributes in attribute files and recipes.
Attribute Types
Attributes in Chef Infra Client determine the value applied to a node during a Chef Infra Client run using six different attributes. Chef Infra Client also collects attribute values from up to five locations.
During a Chef Infra Client, the combination of attribute types and sources makes up to 15 possible competing values available:
default A default attribute has the lowest attribute precedence. It automatically resets at the start of each Chef Infra Client run. In cookbooks, use the default attributes as much as needed.
force_default To ensure that an attribute described in a cookbook is used. Use of the force default attribute. It takes precedence over a default attribute established by a role or an environment.
normal A common attribute is a setting that is stored in the node object. A normal attribute is given precedence over a default attribute.
Override Override attributes have higher attribute precedence than the default, force default, and standard attributes. And is automatically reset at the beginning of every Chef Infra Client run. Override attributes are typically supplied in recipes. But they can also be specified in an attribute file for a role or an environment. Override attributes should be used only when necessary in a cookbook.
force override Use the force override attribute to ensure that an attribute is defined. A cookbook (through an attribute file or a recipe) takes precedence over an override attribute set by a role or an environment.
automatic An automatic attribute comprises data that Ohai identifies. At the start of each Chef Infra Client execution. An automatic attribute cannot be changed and always precedes all other attributes.
Frequently Asked Questions
What is meant by attributes in Chef Infra?
An attribute is a unique feature of a node. The chef-client uses attributes to understand the present status of the node.
What is the purpose of Chef infra?
Chef Infra is a robust automation framework for turning infrastructure into code. Chef Infra automates infrastructure configuration, deployment, and management across your entire network, regardless of scale. Whether in the cloud, on-premises or in a hybrid environment.
What exactly are Chef resources?
Chef resource represents an intended state of the operating system. It is a configuration policy statement. That outlines the desired state of a node to which the present configuration should be changed using resource providers.
What is a cookbook in Chef?
Cookbooks are Chef's fundamental working units. They contain all the specifics connected to working teams. And the ability to modify the configuration and status of any machine deployed as a node on Chef infrastructure.
In Chef, how do you write a recipe?
To create a Chef recipe, you must use the Ruby programming language. A recipe comprises resource definitions that will send instructions to servers.
Conclusion
We learned about attributes in Chef Infra and a bit about Chef Infra in this blog. Check out the blogs below to learn more about Chef infra-related subjects.