JahMyst
JahMyst

Reputation: 1686

Chef - Prevent execution of multiple resources

Let's say I have 3 execute resources 'Create users', 'Install client' and 'Verify client'.

How can I prevent execution of all those resources if one condition is satisfied ?

Something like:

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

Upvotes: 0

Views: 86

Answers (1)

coderanger
coderanger

Reputation: 54191

Use a normal if/unless conditional like in any other Ruby code.

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

Upvotes: 1

Related Questions