【问题标题】:Chef - Call action from other action in LWRPChef - 从 LWRP 中的其他操作调用操作
【发布时间】:2016-06-11 23:24:43
【问题描述】:

我将提供者定义如下:

action :start do
 ...
end

action :stop do 
 ...
end

action :restart do
 ...
end

现在我不想在restart 中重写stopstart 的实现,而是在action :restart 中调用action :stop 然后action :start,如下所示:

action :restart do
  action :stop
  action :start
end

有没有办法做到这一点?

编辑 - 如 Coderanger 回答中所述,解决方案是:

action :restart do 
  action_stop
  action_start
end

【问题讨论】:

    标签: ruby chef-infra lwrp


    【解决方案1】:

    致电action_startaction_stop

    【讨论】:

    • 我想知道怎么了,但是当我把action_stopaction_start放入action :restart时,action :stopaction :start被执行了两次。当我只是粘贴启动/停止代码时,一切都很好。
    • 请参阅以下 pastebin 进行比较:第一个调用每个动作两次,第二个工作正常。 pastebin.com/6r94LMNApastebin.com/3WHwQhNF
    • 我不知道init 中的内容,但它确实会被调用两次。
    • 另外你使用了一堆类变量,我真的不认为你打算这样做。
    • 这是libraries.rb 定义init函数的内容:pastebin.com/qULUAsgk
    【解决方案2】:

    我不确定这是否是正确的答案。我刚刚尝试过这个,它似乎在编译时调用了 action_stop 和 action_start。我试图运行这样的东西:

    action :create do
      # steps to create resource
      directory '/test' do
        ...
      end
    
      action_config
    end
    
    action :config do   
      ... # configuration   
      template '/test/config' do   
        ...   
      end 
    end
    

    它失败了,因为 :config 先运行(在创建目录之前)。

    我尝试将 action_config 放入 ruby​​_block ——这似乎可行,但我不确定参数是否正确传递。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-17
      • 1970-01-01
      • 1970-01-01
      • 2016-08-17
      相关资源
      最近更新 更多