Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Plugins 厨师菜谱没有';找不到ohai插件定义的资源_Plugins_Chef Infra_Ohai Gem - Fatal编程技术网

Plugins 厨师菜谱没有';找不到ohai插件定义的资源

Plugins 厨师菜谱没有';找不到ohai插件定义的资源,plugins,chef-infra,ohai-gem,Plugins,Chef Infra,Ohai Gem,我想向Ohai添加额外的资源“已安装openssh的版本”,以便在我的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 creat

我想向Ohai添加额外的资源“已安装openssh的版本”,以便在我的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
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']} **")
irb中ohai插件的本地测试工作正常。 现在,我尝试检查Chef recipe中的资源可见性

$cat test/recipes/default.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
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客户端

$chef client-z-m test/recipes/default.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
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']} **")
要使附加插件可见,请将行添加到配置文件中

$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/'
问题:

  • 如何正确地为本地和远程执行制作额外的插件?如何检查它是否已经准备好

  • 如何正确地通知chef客户端为本地单一配方运行和远程运行执行ohai附加插件

  • 欢迎任何解释和建议


    Alex

    有几个问题:首先查看如何将ohai插件打包到菜谱中分发。其次,自定义插件中的节点属性仍然需要通过
    节点
    对象访问:
    节点['openssh']['version']
    。第三,记住在Chef()中执行顺序是如何工作的,并且在插件加载并运行之后,自定义属性才可用。

    在google之前签出主流

    这个项目描述了如何在2017年部署你的插件


    谢谢@coderanger,我在/tmp/node.json中的搜索显示没有OpenShyou在编译时生成
    内容的痕迹,这可能是在加载插件之前。把它移到lazy evaluation。谢谢@coderanger,不知怎么的,它是有帮助的,主要是node['openssh']['version']注释。不知何故,我的节点键值输出甚至没有显示在dynamicaly build output=“#{Chef::JSONCompat.to_json_pretty(node.to_hash)}”到/tmp/node.json文件中。有些开发。在本地测试成功后,我试图进行远程执行。它失败,错误为:第14行的nil:NilClass的未定义方法“[]”Chef::Log.info(“===================test cookbook**{node['openssh']['version']}**”),该方法在本地测试中运行正常。在/var/chef/cach/cookbooks/test中的远程节点上也没有找到相关的插件(test/files/default/plugins/openssh.rb)