Following Ron Cowie's guide in his book Customising Chef (O'Reilly) to creating simple Ohai plugin, it appears as though the Ohai plugins_path is not being loaded on my Windows 10 laptop.
Steps are as follows:
- Create Example1.rb plugin file. I have done so in C:\dev\opscode\ohai\plugins\example1.rb
Ohai.plugin(:Example1) do 1 provides "awesome_level" 2 collect_data do 3 awesome_level 100 4 end end
- Run irb and type following:
PS C:\WINDOWS\system32> irb irb(main):001:0> require 'ohai' => true irb(main):002:0> Ohai::Config[:plugin_path] = 'C:/Dev/opscode/ohai/plugins' => "C:/Dev/opscode/ohai/plugins" irb(main):003:0> o = Ohai::System.new => #<Ohai::System:0x0000000003c339a0 @cli=nil, @plugin_path="", @config={},...
It looks to me as though the @plugin_path is empty and so after running o.all_plugins and then o.attributes_print("awesome_level")
> Results in error: irb(main):019:0> puts
> o.attributes_print("awesome_level") Traceback (most recent call last):
> 3: from C:/opscode/chef-workstation/embedded/bin/irb.cmd:19:in `<main>'
> 2: from (irb):19
> 1: from C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.5.0/gems/ohai-14.8.10/lib/ohai/system.rb:178:in
> `attributes_print' ArgumentError (I cannot find an attribute named
> awesome_level!)
Is it syntax for setting the plugins_path on Windows. I tried double-quotes. Backslashes.
My Chef install is not standard and the default C:\chef\ohai\plugins folder did not exist. If i used cmd line to add a directory to plugin path it worked:
This displayed all attributes from all plugins with right at the end my custom plugin