Opscode厨师Ohai插件 – 如何让自定义插件自动运行?

奥海文档不完整。 以下是我迄今为止所能做到的:

  • 我创build了一个自定义插件,添加了一个名为“my_custom_data”的节点数据
  • 它工作时,我手动加载在IRB
  • 我已经使用Ohai烹饪书来将它加载到需要它的服务器上

然而,奥海不加载它,既不在厨师运行,也不是手动运行奥海。

这里的文档对回答这个问题没什么用处。 http://docs.opscode.com/ohai.html

你的问题意味着你已经在使用Ohai食谱分发这个插件了,而且这个工作非常有效 – 也就是说,你的自定义插件最终被安装到/etc/chef/ohai_plugins (默认configuration)。 如果是这样的话,几乎肯定会试图加载插件 – 而插件失败。

Ohai不担心插件失败 – 只是转向下一个插件。

手动运行时,确保你告诉ohai查看额外的插件目录。 这是如何失败(一个自定义的插件称为'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--> 

最后,如果您看不到输出(但没有错误),请启用debugging日志logging并search输出以查找与您的插件关联的部分:

 [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 --> 

您需要确保在/etc/chef/client.rb中有以下行。 如果您正在使用刀引导,您将需要指定一个模板。

 Ohai::Config[:plugin_path] << "/etc/chef/ohai_plugins"