Blog-Icon_5_100x385

Ohai 7.0 Release Candidate

Ohai chefs,

Today we are making available a release candidate for the next major version of Ohai. This release (Ohai 7.0) sets us up for future improvements by resolving current architectural limitations, which will make it easier to build custom plugins.

Huge thanks goes to Claire McQuin and Theodore Nordsieck who made this release a reality during their internships at Chef.

What’s new?

Ohai 7 introduces two major changes.

New Ohai DSL

Ohai 6 had served us well. However, it had an important architectural limitation that prevented us from implementing some cool ideas, such as differentiating collected data as critical or optional. This limitation was because Ohai 6 treated plugins as monolithic blocks of code.

Ohai 7 introduces a new DSL, which makes it easier to write custom plugins, provides better code organization, and sets us up for the future. Here is what an Ohai 7 plugin looks like:

Ohai.plugin(:Name) do
  provides "attribute", "attribute/subattribute"
  depends "kernel", "users"

  def a_shared_method
    # some Ruby code that defines the shared method
    attribute Mash.new
  end

  collect_data(:default) do
    # some Ruby code
    attribute Mash.new
  end

  collect_data(:windows) do
    # some Ruby code that gets run only on Windows
    attribute Mash.new
  end

end

Two important pieces of the new DSL are:

  • collect_data() blocks, which enable better organization of platform-specific code
  • depends / provides statements, which enable easier dependency management among plugins

Read more about the new DSL here.

Attribute name-based user interaction

Previously in order to collect data from individual plugins, users needed to know the file name of the plugins they would like to utilize.

# In Ohai 6 passwd plugin (named passwd.rb) sets the
# 'current_user' attribute and in order to use this 
# data one needs to know this fact. 

require_plugin("passwd")

With Ohai 7, user interaction is now based on the attribute names. Only specify the names of the attributes for which you would like to collect data. Ohai 7 figures out which plugins are required and then collects the data.

# In Ohai 7 one doesn't need to know the underlying 
# details to find out current_user

depends 'current_user'

Future of Ohai

Ohai 7 sets us up to implement a better experience for Chef in the future. Here are some of the ideas that we have in mind for the future of Ohai:

  • Classifying the system information into critical (required for chef runs) and optional (for information only)
  • Failure policies if a critical piece of information can not be gathered on the system
  • Limiting the information collected by Ohai for a node

Backwards Compatibility

Ohai 7 is backwards compatible with existing Ohai 6 plugins. But none of the new (or future) functionality will be available to version 6 plugins. All of your existing plugins will continue to work with Ohai 7. However we recommend planning to migrate Ohai 6 plugins to Ohai 7 as soon as possible in order to make use of the new and future functionality in Ohai.

One of the things that we’ve aimed to achieve is to make it trivial to convert a version 6 plugin to version 7. Here is the small checklist you should go through to convert your plugins to the new version:

  • Pick a name for your plugin and define your plugin as a version 7 plugin
  • Convert required_plugin() calls to depends statements.
  • Move your plugin logic inside a collect_data() block.

Going through these steps a version 6 plugin that looks like this:

provides 'my_app'

require_plugin("kernel")

my_app Mash.new
my_app[:version] = shell_out("my_app -v").stdout
my_app[:message] = "Using #{kernel[:version]}"

will look like this:

Ohai.plugin(:MyApp) do
  provides 'my_app'
  depends 'kernel'

  collect_data do
    my_app Mash.new
    my_app[:version] = shell_out("my_app -v").stdout
    my_app[:message] = "Using #{kernel[:version]}"
  end
end

Chef Integration

Since this is a major version release for Ohai we will leave a longer-than-usual time for Chef integration in order to make sure any issue can be addressed before rolling this major version into your production environments.

Currently Ohai 7 is currently planned to be integrated into Chef for the 11.12.0 release, which is estimated to be released at the end of April 2014.

Give it a spin

We are shipping Ohai 7 Release Candidate as an add-on to Chef 11.8.2. If you would like to give it a spin you can install Chef Client 11.8.2 from here and execute the following commands:

# For windows systems
gem install chef -v 11.8.4.ohai7.0

# For other systems
sudo /opt/chef/embedded/bin/gem install chef -v 11.8.4.ohai7.0

Feedback?

As always remember to reach out to us anytime if you have an issue or a feedback. We are available for you if you’re having problems getting started with Ohai 7, having problems with it or if there is something that you would like to see in Ohai in the future.

Serdar Sutay