Ohai plugin_path未在Windows 10上加载

问题描述 投票:0回答:2

继Ron Cowie在他的书Customizing Chef(O'Reilly)创建简单的Ohai插件之后,看起来似乎没有在我的Windows 10笔记本电脑上加载Ohai plugins_path。

步骤如下:

  1. 创建Example1.rb插件文件。我在C:\ dev \ opscode \ ohai \ plugins \ example1.rb中这样做了
Ohai.plugin(:Example1) do 1
  provides "awesome_level" 2

  collect_data do 3
    awesome_level 100 4
  end
end
  1. 运行irb并输入以下内容:
PS C:\WINDOWS\system32> irb
irb(main):001:0> require 'ohai'
=> true
irb(main):002:0> Ohai::Config[:plugin_path] = 'C:/Dev/opscode/ohai/plugins'
=> "C:/Dev/opscode/ohai/plugins"
irb(main):003:0> o = Ohai::System.new
=> #<Ohai::System:0x0000000003c339a0 @cli=nil, @plugin_path="", @config={},...

它看起来好像@plugin_path是空的,因此在运行on.all插件然后o.attributes print(“awesome level”)之后

> Results in error: irb(main):019:0> puts
> o.attributes_print("awesome_level") Traceback (most recent call last):
>         3: from C:/opscode/chef-workstation/embedded/bin/irb.cmd:19:in `<main>'
>         2: from (irb):19
>         1: from C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.5.0/gems/ohai-14.8.10/lib/ohai/system.rb:178:in
> `attributes_print' ArgumentError (I cannot find an attribute named
> awesome_level!)

是在Windows上设置plugins_path的语法。我试过双引号。反斜杠。

chef ohai-gem
2个回答
0
投票

我的Chef安装不是标准的,默认的C:\ chef \ ohai \ plugins文件夹不存在。如果我使用cmd行将目录添加到插件路径它工作:

ohai -d'C:\ dev \ opscode \ ohai \ plugins'

这显示了我的自定义插件的所有插件的所有属性

},“awesome_level”:100


0
投票

感觉像你遇到版本问题 - 解决任何路径和版本问题,使用bundler并锁定你的rubygems versionsGemfile

这是一个例子:

$ bundle init
Writing new Gemfile to /private/var/folders/_2/rg7rz1h56sb2ln5f75gjr7558b1wz3/T/tmp.PPIvZRXi/Gemfile
$ echo "gem 'ohai'" >> Gemfile
$ bundle install --path vendor/gems --jobs 4
...

你提到你正在使用chef。如果你在chef-client run中使用ohai,那么插件必须安装在由chef管理的节点上,并且在你的配方中加载ohai之前。

© www.soinside.com 2019 - 2024. All rights reserved.