大厨食谱没有找到ohai插件定义的资源

时间:2016-01-27 20:58:49

标签: plugins chef ohai-gem

我想添加其他资源'版本已安装的openssh'到Ohai在我的openssh维护食谱中使用它。

关于RHEL 5.11 Chef 12.4.1 Ohai 8.5.0测试工作站我创建并测试了Ohai插件

$ cat cookbooks/test/files/default/plugins/openssh.rb

Ohai.plugin(:Openssh) do

  provides "openssh"

Ohai::Log.debug('plugin start')

  def create_objects

    openssh Mash.new

  end


  collect_data do

    create_objects

    openssh[:version] = 'ssh -V 2>&1 |head -1| cut -d, -f1| cut -d_ -f2 '

  end

end

irb的ohai插件的本地测试工作正常。 现在我试图检查Chef配方中的资源可见性

$ cat test/recipes/default.rb

file "#{ENV['HOME']}/x.txt" do

  content 'HELLO WORLD'

end

output="#{Chef::JSONCompat.to_json_pretty(node.to_hash)}"

file '/tmp/node.json' do

  content output

end

Chef::Log.info("============ test cookbook ** #{openssh['version']} **")

\#Chef::Log.info("============ test cookbook ** #{node['kernel']} **")

通过运行本地chef-client

$ chef-client -z -m test/recipes/default.rb

要使附加插件可见行添加到配置文件

$grep Ohai ~/.chef/*.rb
~/.chef/client.rb:Ohai::Config[:plugin_path] << '~/chef/cookbooks/test/files/default/plugins/'

~/.chef/knife.rb:Ohai::Config[:plugin_path] << '~/chef/cookbooks/test/files/default/plugins/'

(我明白这太明确了)

尽管使用打印节点[&#39; kernel&#39;]运行正常,但是openssh版本没有运行,调试日志显示:

[2016-01-27T11:48:21-08:00] DEBUG: Cookbooks detail: []

[2016-01-27T11:48:21-08:00] DEBUG: Cookbooks to compile: []

[2016-01-27T11:48:21-08:00] DEBUG: **Loading Recipe File XXX/cookbooks/test/recipes/default.rb**

[2016-01-27T11:48:21-08:00] DEBUG: Resources for generic file resource enabled on node include: [Chef::Resource::File]

[2016-01-27T11:48:21-08:00] DEBUG: Resource for file is Chef::Resource::File

[2016-01-27T11:48:21-08:00] DEBUG: Resources for generic file resource enabled on node include: [Chef::Resource::File]

[2016-01-27T11:48:21-08:00] DEBUG: Resource for file is Chef::Resource::File

[2016-01-27T11:48:21-08:00] DEBUG: Resources for generic openssh resource enabled on node include: []

[2016-01-27T11:48:21-08:00] DEBUG: **Dynamic resource resolver FAILED to resolve a resource for openssh**

[2016-01-27T11:48:21-08:00] DEBUG: Re-raising exception: NameError - No resource, method, or local variable named `openssh' for `Chef::Recipe "XXX/cookbooks/test/recipes/default.rb"'

问题:

  1. 如何为本地和远程执行的配方添加额外的插件?如何检查它是否被抽出并准备好了?

  2. 如何正确通知chef-client为本地单一配方运行和远程运行执行ohai附加插件?

  3. 欢迎任何解释和建议。

    Alex

2 个答案:

答案 0 :(得分:0)

一些问题:首先查看https://github.com/coderanger/ohai-example以了解如何在食谱中打包ohai插件以进行分发。其次,自定义插件的节点属性仍然需要通过node对象访问:node['openssh']['version']。第三,记住Chef(https://coderanger.net/two-pass/)中的执行顺序是如何工作的,并且在插件加载并运行之前,自定义属性才可用。

答案 1 :(得分:0)

google之前的checkout主流!

该项目描述了如何在2017年部署您的插件!

https://github.com/chef-cookbooks/ohai