title: Chef : Opsworks : run rake task
body: <p>My objective is to execute a rake task on my apps running in Opsworks.<br>
  It appears to me that my opsworks cookbook is not running rake from the correct directory. </p>
  
  <p>How can I tell the cookbook to run in the app home dir (so it can pick up the Gemfile)?<br>
  Do I need to specify an RAILS_ENV?  </p>
  
  <p>My cookbooks default.rb:</p>
  
  <pre><code>Chef::Log.info("****** Audit Photo URLS : Running Rake Task ******")
  execute "rake audit:audi_image_urls" do
      command "bundle exec rake audit:audi_image_urls"
  end
  </code></pre>
  
  <p>Errors from Opsworks log:  </p>
  
  <pre><code>[2014-11-28T18:36:33+00:00] INFO: Running queued delayed notifications before re-raising exception
  [2014-11-28T18:36:33+00:00] ERROR: Running exception handlers
  [2014-11-28T18:36:33+00:00] ERROR: Exception handlers complete
  [2014-11-28T18:36:33+00:00] FATAL: Stacktrace dumped to /var/lib/aws/opsworks/cache.stage2/chef-stacktrace.out
  [2014-11-28T18:36:33+00:00] ERROR: execute[rake audit:audi_image_urls] (auditphoto::default line 3) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '10'
  ---- Begin output of bundle exec rake audit:audi_image_urls ----
  STDOUT: Could not locate Gemfile
  STDERR: 
  ---- End output of bundle exec rake audit:audi_image_urls ----
  Ran bundle exec rake audit:audi_image_urls returned 10
  [2014-11-28T18:36:33+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
  </code></pre>