How to extend chef resource?

早过忘川 提交于 2019-12-11 04:09:57

问题


I'm trying to extend Bash resource, so that when I invoke shm_wbash, the command's output is placed in a log file as it runs. Since I don't want to copy all the available parameters to LWRP resource definition, I've tried to extend the original chef Bash resource like this (I'll be omitting the actual payload since that doesn't matter here):

class Chef
  class Resource
    class WBash < Resource::Bash
      def initialize(name, run_context=nil)
        super

        puts 123
      end
    end
  end
end

I've put that to cookbooks/shm/libraries/wbash.rb and when I try to run it, I get No resource or method named 'shm_wbash' forChef::Recipe "test"'`. How do I fix this?


回答1:


Use w_bash

This is what chef is converting the class name to for use in the DSL.



来源:https://stackoverflow.com/questions/23056576/how-to-extend-chef-resource

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!