简体   繁体   English

厨师食谱未找到ohai插件定义的资源

[英]chef recipe doesn't find ohai plugin defined resource

I want to add additional resource 'version of installed openssh' to Ohai to use it in my openssh maintaining recipe. 我想向Ohai添加其他资源“已安装的openssh版本”,以在我的openssh维护配方中使用它。

On RHEL 5.11 Chef 12.4.1 Ohai 8.5.0 test workstation I have created and tested Ohai plugin 在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

Local test of ohai plugin in irb is working fine. irb中的ohai插件的本地测试工作正常。 Now I'm trying to check resource visibility in Chef recipe 现在,我正在尝试检查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']} **")

by running local chef-client 通过运行本地厨师客户端

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

To make additional plugin visible line is added to config files 为了使其他插件可见行被添加到配置文件

$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/'

(I understand that this is too explicit ) (我知道这太明显了)

Although running with printing node['kernel'] is working fine , openssh version is not running with debug log that shows: 尽管使用print node ['kernel']运行正常,但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"'

Questions: 问题:

  1. How properly chef out additional plugin to recipe for local and remote execution? 如何正确地将其他插件配置到配方中以进行本地和远程执行? How to check that it is cheffed out and ready? 如何检查已准备好并准备好了?

  2. How properly notify chef-client to execute ohai additional plugin for local single recipe run and for remote run as well? 如何正确通知厨师客户为本地单个配方运行和远程运行执行其他插件?

Any explanations and suggestions are welcomed. 欢迎任何解释和建议。

Alex 亚历克斯

A few issues: first check out https://github.com/coderanger/ohai-example to see how to package an ohai plugin in a cookbook for distribution. 有几个问题:首先查看https://github.com/coderanger/ohai-example ,看看如何将ohai插件打包在食谱中以进行分发。 Second, node attributes from custom plugins still need to be accessed via the node object: node['openssh']['version'] . 其次,来自定制插件的节点属性仍然需要通过node对象访问: node['openssh']['version'] Third, remember how execution ordering works in Chef ( https://coderanger.net/two-pass/ ) and that the custom attributes won't be available until after the plugin is loaded and run. 第三,请记住执行顺序在Chef( https://coderanger.net/two-pass/ )中的工作方式,并且自定义属性只有在加载并运行插件后才可用。

Checkout mainstream before google! 在Google之前结帐主流!

This project describes how to deploy you plugin in 2017 year! 该项目介绍了如何在2017年内部署插件!

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM