2016-02-29 107 views
0

比方說,我有3個execute資源「創建用戶」「安裝客戶端」「驗證客戶端」廚師 - 多種資源的防止執行

如果滿足一個條件,我該如何防止執行所有這些資源?

喜歡的東西:

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 

回答

1

使用正常if/unless條件像其他任何Ruby代碼。

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 
+0

是的,foodcritic會抱怨這一點。 FoodCritic是錯誤的。 – coderanger