Deploying Custom Ohai Plugins
With the deprecation of the
ohai cookbook, there is some confusion on how to deploy custom Ohai plugins.
This short summary shows, how easy deployments have become.
Before, new plugins for system discovery were used with the Ohai cookbook, which mainly offered the
ohai_plugin resource. Commonly, you could see the following code in cookbooks:
ohai_plugin 'ipaddress' do name 'ipaddress' load_single_plugin true end
This would search your
files/ipaddress.rb plugin, deploy it to the custom plugin directory and reload it to get data. Sometimes, you also find a separate resource in old cookbooks which reloads using the Chef built-in
Many of the outdated Chef tutorials or books will still try to teach you this pattern. But the world moved on…
For several years already(!), using custom plugins has been extremely easy: Just move your plugin into the cookbook
ohai/ directory. That’s it! An additional step in the compile phase will take care of moving the file into the correct spot, loading it and querying the data it returns.
You can remove all that custom plugin installation code and have the same functionality. Of course, any cookbooks depending on the one with the plugin get the correct data as well.
The feature of having a cookbooks directory for Ohai specifically (RFC 59) has been present since Chef Infra Client 13.0, but was not publicly documented until the Chef Server could handle a newer API version. With Chef Infra Server 12.18.14, this support arrived - roughly around the release of Chef Infra v14.6.26.
The exact time of documenting the feature is hard to pinpoint, as the Chef Docs page changed to a Hugo-based blog in early 2020. It has been on the page on cookbook structure at least since then.