Custom Ohai plugin running but not working

Hello,

I am really struggling to get a custom Ohai plugin to work in Windows.

Here is my custom plugin:

Ohai.plugin(:Chris) do
  provides "chris"

  collect_data do
    chris = Mash.new unless chris
    chris = "why doesn't this work!"
    Ohai::Log.debug(chris)
  end

end

Here is the recipe I’m using to deploy it:

include_recipe "chef-client::config"

ohai_plugin 'chris' do
  path 'C:\chef\ohai\plugins'
  action :create
end

I can see that it gets deployed to c:\chef\ohai\plugins.

If I go to the PC and run ohai directly, I can see the following output:
PS C:\chef> ohai -l debug
[removed irrelevant log lines]
[2018-03-22T13:32:43+00:00] DEBUG: why doesn’t this work!
[2018-03-22T13:32:43+00:00] DEBUG: Plugin Chris took 0.0 seconds to run.

The Ohai output has no ‘chris’ attributes. I’m at my wits end. Any advice or thoughts?

Thank you,
Chris

identifier = value sets a local variable in ruby. In ruby generally, if something has a setter (i.e., a method ending with an =), then you need to give it an explicit receiver, e.g., object.some_attribute = new_value. In Chef specifically, we use a bit of magic to make most things you use combined getter-setters, so the syntax is some_attribute(new_value) and since ruby lets you omit the parentheses, the most common form is some_attribute new_value, like you have in your recipe code.

1 Like

@kallistec Thank you! That was exactly it.
[deletia]
“chris”: “why doesn’t this work!”
}
[2018-03-22T14:15:08+00:00] DEBUG: Ohai took 0.86 total seconds to run.

I have been writing a lot of Python lately and moving between it and Ruby is messing with my head. :cold_sweat: