Introduction
Ohai is a tool that captures almost all configuration data about your system when run stand-alone or executed as one of the first steps during a chef-client run. Ohai is run by the chef-client at the beginning of every Chef run to determine system state.
$ ohai
This command returned a huge JSON object file that contain many specific host details like host names, ip address, cpu info, memory, network etc.
....
"kernel": {
"name": "Linux",
"release": "4.15.17-1-pve",
"version": "#1 SMP PVE 4.15.17-9 (Wed, 9 May 2018 13:31:43 +0200)",
"machine": "x86_64",
"processor": "unknown",
"os": "GNU/Linux",
"modules": {
"cpuid": {
"size": "16384",
"refcount": "0"
},
"nf_conntrack_ipv6": {
"size": "20480",
"refcount": "0"
},
.....
If you want to run one of the plugins you can provide it as an argument.
$ ohai hostname
Output:
[
"localhost"
]
These details can be gatered with Ohai and it’s very importaint to understaind how we can use it inside the recepies. Chef Client executes autamaticlly Ohai and stores data about the node in a object you can use within the recipes names node.
The Node object
It’s a representation of system and stores all values as attributes found about the system.
ipaddress: 127.0.0.0
IPADDRESS: node['ipaddres']
Instead hardcoding values for ipadress
or hostname
inside recipe, we can use reference (the Node object). We will call node hostname:
node['hostname']
Also, we can call child elements. For example, for memory usage:
node['memory']['total']
All these information we can use inside our recipes.
When set -minimal-ohai
, Chef will only run the bare minimum Ohai plugins necessary to support node name detection and resource/provider selection. With these option we want to speed up Chef’s integration tests
which run chef-client
many times in various contexts,
however advanced users may find it useful in certain use cases.
Whitelist
Allows you to provide a whitelist of node attributes to save on the server. All of the attributes are still available throughout the chef run, but only those specifically listed will be saved to the server.