2

(对不起链接,我不能发布超过两个..)我正在尝试将提供程序添加到包含另一个包含 LWRP 的食谱的食谱中。

包装好的食谱是平衡 Python 主管:[github.com/poise/supervisor.git][1] 我正在使用 Berkshelf 指向 Chef 来导入它:

source "...api.berkshelf.com"
source '....<my chef/berkshelf server>:26200'

cookbook 'supervisor', github: "poise/supervisor"

metadata

在我的食谱中:

.
.
    include_recipe 'supervisor'
.
.

..我希望通过“新”操作向其中一个主管资源添加提供者。

以下是“导入”的提供者:[github.com/poise/supervisor/blob/master/providers/service.rb][1]

我希望添加另一个名为 action “reload” 的提供程序,最终将调用supervisorctl reread

我在这里和那里尝试了很多例子,但没有运气:来自 gitHub:chef_extend_lwrp

我试过 docs.chef.io lwrp_custom_provider_ruby 和 neethack.com/2013/10/understand-chef-lwrp-heavy-version/

并试图模仿 Seth Vargo 的答案和示例:github.com/opscodecookbooks/jenkins/blob/8a2fae71cd994704b09924e9a14b70b9093963a3/libraries/credentials_password.rb

github.com/poise/supervisor/blob/master/providers/service.rb

github.com/poise/supervisor.git

但看起来 Chef 没有正确导入代码:

ERROR: undefined method `action' for Chef::Resource::SupervisorServices:Class

当我将我的库导入写为:(my_enable_service 已定义但我已将其从本示例中删除)

def whyrun_supported?
  true
end


class Chef
  class Resource::MyupervisorService < Resource::SupervisorService
    provides :my_supervisor_service
    actions :reload
    @resource_name = :my_supervisor_service
  end
end


class Chef
  class Provider::MyupervisorService < Provider::SupervisorService
    action :reload do
      converge_by("Enabling #{ new_resource }") do
        my_enable_service
      end
    end



  end
end


Chef::Platform.set(
  resource: :my_supervisor_service,
  provider: Chef::Provider::MyupervisorService
)

我的食谱名称是:“my_supervisor”,我的库文件是“service.rb”

我也尝试过来自 stackoverflow 的许多答案,但我无法在此处发布,因为我缺乏声誉点 :( 我已经看到了很多来自 Seth Vargo 的参考资料,我希望他会看到我的问题;)

4

1 回答 1

1

好的,在玩了一段时间之后(对我来说听起来很有趣),我明白这里出了什么问题。

引用文档:

首先加载库以确保所有语言扩展和 Ruby 类对所有资源都可用。接下来,加载属性,然后是轻量级资源,然后是所有定义(以确保定义中的任何伪资源都可用)。

下面的文件cookbook/libraries是在构造 lwrp 类之前加载的,这就是为什么你最终得到一个 unknow 方法的原因,当你在 my_supervisor 中的库被编译时,SupervisorService 类还没有加载,所以你最终得到一个Object不知道的简单动作方法。

我能想到的最佳解决方法是在您的配方中管理案例,根据您的操作调用执行资源或 lwrp。

如果您真的认为它应该成为主管操作的一部分,请克隆食谱存储库,添加操作并发出拉取请求。

于 2015-01-19T08:45:44.567 回答