Attributes & precedence
Where node values come from.
Attributes are the data that parameterize cookbooks — the port to listen on, the number of workers, the packages to install. They can be set in many places (cookbook attribute files, roles, environments, the node itself, recipes) and, like Ansible variables, that flexibility comes with a precedence hierarchy. Chef’s precedence has levels — default, force_default, normal, override, force_override, automatic — and the highest set level wins.
default['nginx']['worker_processes'] = 4default['nginx']['port'] = 80# used in a recipe or template as node['nginx']['port']
Automatic attributes (ohai)
At the start of every run, a tool called ohai profiles the node and produces automatic attributes — the highest precedence, and un-overridable — describing the platform, network, memory, CPUs, and more. You read them (node[‘platform_family’], node[‘memory’][‘total’]) to write portable recipes, exactly as you use Ansible facts. Automatic attributes always win because they are ground truth about the machine.
pkg = node['platform_family'] == 'debian' ? 'apache2' : 'httpd'package pkg# scale workers to the node's real CPU count (an automatic attribute)node.default['nginx']['worker_processes'] = node['cpu']['total']