0

按照 Ron Cowie 在他的书定制厨师 (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 好像是空的,所以在运行 o.all_plugins 然后 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 的语法吗?我试过双引号。反斜杠。

4

2 回答 2

0

在我看来,您遇到了版本问题 - 要解决任何路径和版本问题,请使用并将您的ruby​​gems版本bundler锁定在. Gemfile

这是一个例子:

$ 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 运行中使用 ohai,那么插件必须安装在由 chef 管理的节点上并且在 ohai 被加载到您的食谱之前。

于 2019-03-23T14:25:41.043 回答
0

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

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

这显示了所有插件的所有属性,最后是我的自定义插件

}, "awesome_level": 100

于 2019-03-22T11:42:32.673 回答