Creede
Creede

Reputation: 153

Ohai thinks my plugin is version 6. Why?

I'm trying to write a plugin for ohai. It seems like a pretty straightforward task:

Ohai.plugin(:Uname) do
  provides 'uname'
  depends 'kernel'

  collect_data do
    uname Mash.new
    uname[:message] = `uname -a`
  end
end

To me this looks like the online examples provided by Opscode, O'Reilly and others. But here's what happens when I try to test it:

 % irb -rohai
irb(main):001:0> Ohai::Config[:plugin_path] << "."
=> ["/home/ll0359/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/ohai-8.3.0/lib/ohai/plugins", "."]
irb(main):002:0> o = Ohai::System.new
=> #<Ohai::System:0x007fed82e43078 @plugin_path="", @data={}, @provides_map=#<Ohai::ProvidesMap:0x007fed82e42fd8 @map={}>, @v6_dependency_solver={}, @d82e42f38 @controller=#<Ohai::System:0x007fed82e43078 ...>, @v6_plugin_classes=[], @v7_plugin_classes=[]>, @runner=#<Ohai::Runner:0x007fed82e42ec0 @prp:0x007fed82e42fd8 @map={}>, @safe_run=true>>

irb(main):003:0> o.all_plugins

And here's where the fun begins. I get this output, over and over and over:

[2015-05-20T03:13:09+00:00] WARN: Plugin Definition Error: <./ohai_uname.rb>: collect_data already defined on platform default
[2015-05-20T03:13:09+00:00] WARN: [DEPRECATION] Plugin at ./test_ohai.rb is a version 6 plugin. Version 6 plugins will not be supported in future releases....
your plugin to version 7 plugin syntax. For more information visit here: docs.chef.io/ohai_custom.html

(the text on my second line was clipped by my screen but you get the idea)

I've tried running this code with and without the 'depends' line. Same result.

I've tried running this code with and without the Mash line, substituing 'uname uname -a' for the assignment line. Same result.

I've tried running with and without passing ":linux" as a parameter to collect_data. The only difference is I get a warning about collect_data(:linux) already being defined instead of :default.

I've tried renaming the plugin to a random 8 character identifier just in case it was tripping over being called :Uname. Same result.

I've tried passing "uname" (capital and lower) as a parameter to o.all_plugins. Same result.

So my questions are:

  1. Why does ohai (8.3, running under Ruby 2.2.1) think this is a version 6 plugin? I can't see anything in it that would make it look like it's not version 7.

  2. How can I get this working?

Thanks

Upvotes: 0

Views: 622

Answers (1)

Creede
Creede

Reputation: 153

Note to self: Next time you do this, don't try to test from the directory your plugin is in and add "." to your plugin_path. Moving to a different directory and adding the absolute path to the plugin solved the problem.

I plan to leave this up in case someone else has this happen to them.

Upvotes: 3

Related Questions