Chapter 4. Extending Ohai
As we saw in Chapter 3, during the initial stage of the Chef run process (described in Get Configuration Data) Chef runs the Ohai tool to build up a collection of data about the node, which is saved on the Chef server as part of the node object. Ohai is installed as part of the Chef installation process and must be present on a node for chef-client or chef-solo to function correctly.
The core Ohai tool is driven by its flexible and powerful plugin interface. Out of the box, Ohai ships with a number of useful plugins that collect data on various generic aspects of the underlying system, such as the hardware, operating system, and networking configuration.
The power of Ohai’s plugin framework, however, comes from the fact that it allows us to define our own plugins to augment the information stored about our nodes on the Chef server. Say, for example, we want our nodes to define an attribute stating whether they are virtual machines (VMs) or physical servers, so that our recipes only install VM-specific packages on nodes that need them. Perhaps we want to add a node attribute that fetches the physical location of a node from an asset management system so that we can make use of this logic in our recipe code. Out of the box, Ohai does not collect any of this data—but we can easily create our own plugins that do.
Much in the same way as the Chef Recipe domain-specific language (DSL) provides us with a number of useful resource blocks to abstract away the complexities ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access