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.

User-Managed Plugins

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

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 ohai resource.

Many of the outdated Chef tutorials or books will still try to teach you this pattern. But the world moved on…

Chef-Managed Plugins

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.

Similar Posts You Might Enjoy

Air-Gapped Compliance Scans with InSpec

Chef InSpec offers the possibility to scan any type of device using community-authored compliance profiles. As InSpec needs to connect to the machines, networking and firewall rules make this task tricky in bigger environments. With the newly released train-awsssm plugin, this situation changes drastically. Read on, if you want to know how. - by Thomas Heinen

Mocking data in Test Kitchen (Part 2)

Going beyond the easier use case of mocking attributes and databags, we sometimes want to fake some data about the system itself. - by Thomas Heinen

Mocking data in Test Kitchen

The more complex your cookbooks, the bigger the need to supply some external information to your test machines. Passing specific attributes, values of databags or secrets for testing become necessary. We will go through these use cases and show how to mock the data in this post. - by Thomas Heinen