【问题标题】:Execute Chef recipe code if previous code block succeeds如果前一个代码块成功,则执行 Chef 配方代码
【发布时间】:2016-08-07 08:45:13
【问题描述】:

我希望第二个代码仅在第一个返回 0 状态(成功)时执行。

execute 'make dir' do
   command 'mkdir foo'
   action :run
end
execute 'make dir2' do
 command 'mkdir bar'
 action :run
end

【问题讨论】:

    标签: ruby chef-infra


    【解决方案1】:

    首先,您应该使用本地 Chef 资源来创建目录等。应尽可能避免脱壳,因为它绕过了 Chef 的幂等性以及其他问题。

    其次,如果你的第一个资源失败,厨师客户端将退出,所以后续资源显然不会完成,除非你为资源添加一个忽略失败的属性。

    但是,这可能是您想要的:

    directory 'bar' do
      action :nothing
    end
    
    directory 'foo' do
      action :create
      notifies :create, 'directory[dir2]', :immediately
      ignore_failure true
    end
    

    【讨论】:

    • ignore_failure 几乎从来都不是你想要的:)
    • 是的,我从不将它用于我的制作内容,但 耸耸肩
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-12
    • 1970-01-01
    • 2018-05-21
    • 1970-01-01
    • 2015-06-02
    • 2020-12-12
    • 2012-01-12
    相关资源
    最近更新 更多