2

我正在定义一个提供者,如下所示:

action :start do
 ...
end

action :stop do 
 ...
end

action :restart do
 ...
end

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

action :restart do
  action :stop
  action :start
end

有没有办法做到这一点?

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

action :restart do 
  action_stop
  action_start
end
4

2 回答 2

4

呼叫action_startaction_stop

于 2016-02-29T04:36:47.727 回答
0

我不确定这是否是正确的答案。我刚刚尝试过这个,它似乎在编译时调用了 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 - 这似乎有效,但我不确定参数是否正确传递。

于 2017-01-16T16:41:15.253 回答