wfdeller
wfdeller

Reputation: 1

Chef file evaluation only_if

Attempting to File.readlines fails at converge even with 'only_if' check:

ruby_block 'set_archive_mode' do
  only_if (File.exists?(node['ORACLE_DATABASE']['ORACLE_ADMIN'] + '/' + 
  node['ORACLE_DATABASE']['ORACLE_SID'] + '/database_archive_verify.test'))
  if File.readlines(node['ORACLE_DATABASE']['ORACLE_ADMIN'] + '/' + 
  node['ORACLE_DATABASE']['ORACLE_SID'] + 
  '/database_archive_verify.test').grep(/^NOARCHIVELOG/).size > 0
      node.run_state['archive_mode'] = 'noarchivelog'
  else
      node.run_state['archive_mode'] = 'archivelog'
  end
end

The code just needs to set a node.run_state transient attribute based on the contents of the file. I've tried several different approaches all resulting in various errors. The above code include 'only_if', but the File.readlines is still being evaluated at converge.

Upvotes: 0

Views: 541

Answers (1)

Szymon
Szymon

Reputation: 1525

You are using ruby_block wrong, your "readlines" code should be put in the block attribute.

Upvotes: 1

Related Questions