4

The Ohai docs are incomplete. Here's what I've been able to do so far:

  • I've created a custom plugin that adds one piece of node data called "my_custom_data"
  • it works when I load it manually in IRB
  • I've used the Ohai cookbook to get it loaded on the servers that need it

However, Ohai doesn't load it, neither during Chef runs nor if I run Ohai manually.

The docs, here, are of little use in answering this question. http://docs.opscode.com/ohai.html

Shane Madden
  • 114,520
  • 13
  • 181
  • 251
JDS
  • 2,598
  • 4
  • 30
  • 49
  • Why the downvote? How can I improve this question? – JDS Jun 26 '13 at 17:18
  • The question could be improved by adding details about what you've tried, and how it failed. I personally use the ohai cookbook to distribute (and load) custom plugins, and it works just fine. Still, I've added an answer below that offers a few tips - hopefully one helps! – zts Jul 25 '13 at 22:23

2 Answers2

3

Your question implies that you're already using the Ohai cookbook to distribute the plugin, and that that much is working - ie, your custom plugin ends up installed to /etc/chef/ohai_plugins (in the default configuration). If that's the case, it's almost certainly trying to load the plugin - and the plugin is failing.

Ohai doesn't worry about failing plugins - it simply moves on to the next one.

When running by hand, make sure you're telling ohai to look in the additional plugin directory. Here's how that fails (for a custom plugin called 'aws'):

[zts@ip-172-31-39-167 ~]$ ohai aws
[2013-07-25T22:14:53+00:00] INFO: [inet6] no default interface, picking the first ipaddress
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/ohai-6.16.0/lib/ohai/system.rb:247:in `attributes_print': I cannot find an attribute named aws! (ArgumentError)
    from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/ohai-6.16.0/lib/ohai/application.rb:101:in `block in run_application'
    from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/ohai-6.16.0/lib/ohai/application.rb:100:in `each'
    from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/ohai-6.16.0/lib/ohai/application.rb:100:in `run_application'
    from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/ohai-6.16.0/lib/ohai/application.rb:75:in `run'
    from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/ohai-6.16.0/bin/ohai:51:in `<top (required)>'
    from /usr/bin/ohai:23:in `load'
    from /usr/bin/ohai:23:in `<main>'

[zts@ip-172-31-39-167 ~]$ ohai aws -d /etc/chef/ohai_plugins
[2013-07-25T22:15:05+00:00] INFO: [inet6] no default interface, picking the first ipaddress
{
  "region": "eu-west-1",
  "rds": {
<--snip-->

Finally, if you're seeing no output (but no errors), enable debug logging and search through the output to find the part associated with your plugin:

[zts@ip-172-31-39-167 ~]$ ohai aws -d /etc/chef/ohai_plugins -l debug
[2013-07-25T22:17:24+00:00] DEBUG: Loading plugin os
[2013-07-25T22:17:24+00:00] DEBUG: Loading plugin kernel
[2013-07-25T22:17:24+00:00] DEBUG: Loading plugin ruby
[2013-07-25T22:17:24+00:00] DEBUG: Loading plugin languages
<-- huge amounts of logs removed -->
[2013-07-25T22:18:21+00:00] DEBUG: Loading plugin aws
<-- way more logs here -->
zts
  • 945
  • 5
  • 8
1

You need to make sure that you have the following line in /etc/chef/client.rb. If you are using knife bootstrap, you will need to specify a template.

Ohai::Config[:plugin_path] << "/etc/chef/ohai_plugins"
Scott Pack
  • 14,907
  • 10
  • 53
  • 83
user190490
  • 11
  • 1