【问题标题】:Ohai plugin_path not being loaded on Windows 10Ohai plugin_path 未在 Windows 10 上加载
【发布时间】:2019-03-22 09:53:56
【问题描述】:

按照 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 好像是空的,所以在运行 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 的语法吗?我试过双引号。反斜杠。

【问题讨论】:

    标签: chef-infra ohai-gem


    【解决方案1】:

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

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

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

    }, "awesome_level": 100

    【讨论】:

      【解决方案2】:

      我觉得您遇到了版本控制问题——要解决任何路径和版本问题,请使用 bundler 并将您的 rubygems versions 锁定在 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 加载到您的食谱之前。

      【讨论】:

        猜你喜欢
        • 2015-10-27
        • 2021-08-13
        • 1970-01-01
        • 2021-01-02
        • 2018-04-17
        • 1970-01-01
        • 2020-06-12
        • 2020-07-19
        • 2015-09-06
        相关资源
        最近更新 更多