How to distribute a custom Ohai plugin

I am writing an Ohai plugin to add some custom attributes to be used by the chef client. Where can I include the plugin.rb file?

Is it inside a cookbook?

Or do I need to copy it to some standard location?

The docs and other chef lessons don't offer much information about this information (or I must have missed a huge obvious fact). I know that in Puppet, you can include custom facts in the lib / facter / folder of the module. Is it the same in a chef?

+3


source to share


2 answers


It's not as difficult as it sounds, but I agree that the Ohai 7 docs are missing a bit of information that was present in the Ohai 6 docs .

However, the ohai

resource
and the ohai cookbook are what you are looking for. An example of using this method can be found in my recipe .



Basically, you first need to insert the plugin file .rb

into the Ohai ( node[:ohai][:plugin_path]

) plugin path , and then reload Ohai to make the attributes available for the current chef run:

ohai "reload" do
  action :reload
end

template "#{node[:ohai][:plugin_path]}/myplugin.rb" do
  notifies :reload, "ohai[reload]"
end

      

+6


source


The workflow for using ohai custom plugins has changed many times over the years. This chef. It's okay for a chef!

Make sure you are using the latest Ojai cookbook first (currently 5.2.0)

If you are using a chef server, you can do it like this:

knife cookbook site download ohai
cd ~/you/cookbooks/folder
tar xzf ohai-5.2.0.tar.gz
rm ohai-5.2.0.tar.gz
knife cookbook upload ohai

      

There are no cases of using custom plugins on the official site .

Let's assume you already have a plugin (ooh version 7) to deploy.



Incorporate it into any app / wrapper cookbook you want with the following recipe:

ohai_plugin 'myplugin_status_ohai_plugin'

      

And places in your application / wrapper cookie folder a file with your plugin code in files/default/myplugin_status_ohai_plugin.rb

. And it's all. By default, your plugin will be installed in a directory called "plugins" under the "ohai" directory in the Chef configuration directory. The collection of assembly and connection data will run at compile time.

If you do not specify /etc/chef/ohai/plugins

as an additional path in the chef-client setup will be warned. But /etc/chef/ohai/plugins

will be used by default.

To get rid of the warning, use chef-client

cookbook, recipe chef-client::config

, node variable node['ohai']['plugin_path']

as an additional path to download Ohai plugins from.

0


source







All Articles