[chef] Chef mangling bash command?


Chronological Thread 
  • From: Michael Glenney < >
  • To:
  • Subject: [chef] Chef mangling bash command?
  • Date: Wed, 27 Jun 2012 13:48:47 -0700

I have an issue with nastly bash command I'm trying to get chef to execute and it's not working properly, but if I run the same command from the command line it works without errors and does what I expect.  Here's resource:

bash "Set newrelic java options" do
  user "root"
  group "root"
  cwd glassfishconfig
  code <<-EOH
  awk -v searchterm="<java-config" -v payload=" <jvm-options>-javaagent:#{newrelic_dir}/newrelic-#{node[:newrelic][:version]}/newrelic.jar</jvm-options>\n <jvm-options>-Dnewrelic.config.file=#{newrelic_dir}/#{node[:app][:key]}/newrelic.yml</jvm-options>\n <jvm-options>-Dnewrelic.config.log_file_path=#{newrelic_dir}/#{node[:app][:key]}/logs</jvm-options>" '{ if ($0 ~ searchterm) print $0 "\n" payload; else print $0 }' domain.xml.newrelic.bak > domain.xml
  EOH
  action :nothing
end
and here's the error:

---- Begin output of "bash" "/tmp/chef-script20120627-8350-r7jiup" ----
STDOUT:
STDERR: awk: { if ($0 ~ searchterm) print $0 "
awk: ^ unterminated string
---- End output of "bash" "/tmp/chef-script20120627-8350-r7jiup" ----

I am not able to use a template in this case (just saying because that was suggested on IRC).

Unfortunately, when using debug logging the command that is run isn't shown and there's no way I know of to tell chef-client to leave behind the /tmp/chef-script#### files (though this should be an option or happen automatically when debug logging is used because without it you can't properly troubleshoot this type of issue).  I've been told in the past chef passes the command along "as it is in the resource" to the temp script and just runs it but obviously that isn't the case.

I've tried different variations of the above script including escaping all double and single quotes but doesn't help.  Does anyone have an additional insight or suggestions?  I could just drop it into a shell script and include it as a cookbook file but it should work as I have it above.  Plus I'd really like to know what the "gotcha's" are when using the script resources (what needs to be escaped, what doesn't, what won't work at all, etc.) but I haven't found anything in the documentation about it.

Thanks,

Mike G.






Archive powered by MHonArc 2.6.16.

§