Skip to content
Advertisement

Chef – using a for loop with SQLEOH

I have a bash resource which is failing when attempting to loop through some ddl scripts. The same syntax without a for loop (and literal script name) works fine in Chef, and it all works including with the for loop in a terminal:

bash "run_ddl_create_tenants" do
user "#{ENV['CHEFUSER']}"
environment "PATH" => "/usr/lib/oracle/12.1/client64/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/aws/bin:/opt/aws/bin:/home/#{ENV['CHEFUSER']}/bin"
code <<-EOH
  for f in $(grep '>' /tmp/diffs/tnntdiff | cut -c 3-); do
    sqlplus "admin/password@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=$(aws rds describe-db-instances --db-instance-identifier #{ENV['CLIENTID']}-#{ENV['CTCENV']} | grep 'Address' | cut -d\" -f4))(PORT=#{ENV['DBPORT']}))(CONNECT_DATA=(SID=#{ENV['CLIENTID']}#{ENV['CTCENV']})))" <<-SQLEOH
      @#{ENV['CTC_CONFIGURATION']}/ddl/ddl_create_tenant_$f.sql
      #{ENV['DBPASSWD']}
      exit;
    SQLEOH
  done
  EOH
end

The errors I am getting indicate a problem with the SQLEOH delimiter and unexpected end-of-file.

STDERR: /tmp/chef-script20151012-25490-16o11q7: line 7: warning: here-document at line 2 delimited by end-of-file (wanted `SQLEOH')
/tmp/chef-script20151012-25490-16o11q7: line 8: syntax error: unexpected end of file

What is the disconnection between the terminal commands and the way Chef is interpreting this resource?

Advertisement

Answer

Got it, issue of whitespaces preceding the delimiter. Removed indentation on SQLEOH and connected successfully

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement