Debug Ohai plugins in irb shell

178 Views Asked by At

I've installed a chef-workstation on my computer.

 ohai --version #returns: 15.7.4

I also installed the Ohai cookbook from the supermarket. If I integrate this into my test cookbook, the self-written Ohai plug-in will be executed as expected.

Now I want to try to use Ruby

s "irb" shell to debug the self-written ohai plugin step by step. 

Unfortunately 

    irb
    > require 'ohai'  # ==> true
    > Ohai::Config[:plugin_path] << '/home/ohai_plugins'

produces the error message "LoadError (NoMethodError (undefined method <<' for nil:NilClass)". When I use

>  Ohai::Config[:plugin_path] = '/home/ohai_plugins'
>  #=> "/home/ohai_plugins"

it seems to work. But installing the system shows that there is no plugin_path installed...

> o = Ohai::System.new
> #<Ohai::System:0x000055a67d5055b8 @cli=nil, @plugin_path="", @config={}

When I try to get further the attribute from my test Ohai plugin can not be found.

> o.all_plugins
> o.attributes_print("awesome_level") 
> #ArgumentError (I cannot find an attribute named awesome_level!)
1

There are 1 best solutions below

0
On

try the following

require 'ohai'
Ohai::Config[:plugin_path] << '/home/ohai_plugins'
ohai = Ohai::System.new
ohai.all_plugins