为包装的食谱添加提供者或扩展LWRP

时间:2015-01-19 08:15:04

标签: ruby import chef lwrp

(抱歉链接,我不能发布超过两个..) 我正在尝试将一个提供者添加到另一本包含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'
.
.

..我希望通过&#34; new&#34;添加一个提供商给其中一个主管资源。动作。

以下是&#39;导入&#39;供应商: [github.com/poise/supervisor/blob/master/providers/service.rb][1]

我希望添加另一个名为action&#34; reload&#34;这将最终调用 supervisorctl重读

我从这里到那里尝试过很多例子,但没有运气: 来自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
)

我的食谱名称是:&#34; my_supervisor&#34;我的库文件是&#34; service.rb&#34;

我也尝试过stackoverflow的很多答案,但我不能在这里发帖,因为我缺乏声望点:( 我见过Seth Vargo的许多参考文献,我希望他能看到我的问题;)

1 个答案:

答案 0 :(得分:1)

好的,经过一段时间玩这个(听起来很有意思)我明白这里出了什么问题。

引用文档:

  

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

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

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

如果您确实认为它应该是主管操作的一部分,请克隆cookbook repo,添加操作并发出拉取请求。

相关问题