1.

How can you collect extra details about Chef node apart from the ones collected via generic Ohai Plugins?

Answer»

Ohai framework provides a  mechanism to create our own customised plugins to get more details about a Chef Node. For EG: if we want to find out if a Chef node is a virtual machine or not, no Ohai plugin gathers this INFORMATION so we need to create a plugin for the same. Ohai MAKES uses of Ruby-based DSL to create plugins. Ohai plugins are usually kept in “lib/ohai/plugins” directory in the REPOSITORY. A sample Ohai plugin will look like below:

Ohai.plugin(:Sample) do    provides "level"    collect_data do      level 100    end end

where 

  • name of the plugin “Sample” is passed to Ohai.plugin method
  • “provides” method has a list of attributes our plugin provides. Here “level” is the attribute provided.
  • “collect_data” block is executed when a plugin is run by Ohai. In our example, the “level” attribute is set as 100.

Ohai plugins are tested in IRB Ruby shell. This helps us to run plugins WITHOUT performing actual Chef Client runs or configuring nodes. After testing is complete and we need to run the plugins we have to specify the path of the new plugin by specifying Ohai::Config[:plugin_path] << /location/of/plugins line in client.rb or solo.rb file. This helps Ohai to load the plugins  correctly



Discussion

No Comment Found