【问题标题】:Chef - Prevent execution of multiple resourcesChef - 防止执行多个资源
【发布时间】:2016-02-29 12:51:47
【问题描述】:

假设我有 3 个execute 资源'创建用户''安装客户端''验证客户端'。 p>

如果满足一个条件,我如何防止执行所有这些资源?

类似:

block 'Manage client' do 
    execute 'Create users' do
      cwd      scripts_path
      command  './installClient.sh -create_users'
    end
    execute 'Install client' do
      cwd      scripts_path
      command  '/installClient.sh -installClient'
    end
    execute 'Verify client' do
      cwd      scripts_path
      command  './installClient.sh -verifyClient'
    end
    not_if { ::File.exists?('/tmp/client_configured_success') }
end

【问题讨论】:

    标签: ruby chef-infra recipe


    【解决方案1】:

    像在任何其他 Ruby 代码中一样使用普通的 if/unless 条件。

    unless File.exist?('/tmp/client_configured_success')
        execute 'Create users' do
          cwd      scripts_path
          command  './installClient.sh -create_users'
        end
        execute 'Install client' do
          cwd      scripts_path
          command  '/installClient.sh -installClient'
        end
        execute 'Verify client' do
          cwd      scripts_path
          command  './installClient.sh -verifyClient'
        end
    end
    

    【讨论】:

    • 是的,foodcritic 会抱怨这个。美食评论家错了。
    猜你喜欢
    • 1970-01-01
    • 2015-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-11
    • 2016-02-21
    • 1970-01-01
    相关资源
    最近更新 更多