0

I am encountering issue with assets pre-compiling through chef recipe .

my recipe block contains

execute "rake assets:precompile" do   
cwd current_release_directory    
command "bundle exec rake assets:precompile  --trace"    
environment "RAILS_ENV" => "production"    
end

and database.yml file contains ,

production:    
  adapter: mysql2    
  encoding: utf8    
  reconnect: true    
  database: <%= ENV['production_db'] %>     
  pool: 25     
  username: <%= ENV['production_username'] %>    
  password: <%= ENV['production_password'] %>    
  socket: /var/run/mysqld/mysqld.sock    
  host: <%= ENV['production_host'] %>       

when i run the recipe , i am getting the following error .

  Compiled Resource:    
  ------------------    
  # Declared in /var/chef/cache/cookbooks/env_setup/recipes/default.rb:255:in `from_file'     

  execute("rake assets:precompile") do     
    action "run"    
    retries 0     
    retry_delay 2    
    guard_interpreter :default     
    command "bundle exec rake assets:precompile  --trace"    
    backup 5    
    cwd "/home/ubuntu/apps/new_spree_st/current"    
    environment {"RAILS_ENV"=>"production"}    
    returns 0    
    cookbook_name "env_setup"    
    recipe_name "default"    
  end    


Running handlers:    
[2014-12-03T18:38:04+05:30] ERROR: Running exception handlers    
Running handlers complete    
[2014-12-03T18:38:04+05:30] ERROR: Exception handlers complete    
[2014-12-03T18:38:04+05:30] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out    
Chef Client failed. 16 resources updated in 139.571723545 seconds    
[2014-12-03T18:38:04+05:30] ERROR: execute[rake assets:precompile] (env_setup::default line     255) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'    
---- Begin output of bundle exec rake assets:precompile  --trace ----    
STDOUT: Your Gemfile lists the gem hiredis (~> 0.4.5) more than once.    
You should probably keep only one of them.    
While it's not a problem now, it could cause errors if you change the version of just one of them later.    
STDERR: ** Invoke assets:precompile (first_time)    
** Execute assets:precompile    
/opt/chef/embedded/bin/ruby /usr/local/rvm/gems/ruby-2.0.0-p481/bundle/ruby/1.9.1/bin/rake   assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace    
** Invoke assets:precompile:all (first_time)    
** Invoke assets:cache:clean (first_time)    
** Invoke assets:environment (first_time)    
** Execute assets:environment    
** Invoke environment (first_time)    
** Execute environment    
rake aborted!    
Psych::SyntaxError: (<unknown>): could not find expected ':' while scanning a simple key at line 11 column 3    

What might be the problem?

rastasheep
  • 10,416
  • 3
  • 27
  • 37
mbdvg
  • 2,614
  • 3
  • 21
  • 39

2 Answers2

1

You must add to environment production_username, production_password and production_host, because when you run bundle exec rake command database.yml is populated with values from your environment.

Basically you got that error because your database.yml is empty for that values.

rastasheep
  • 10,416
  • 3
  • 27
  • 37
0

An easy fix is to add fallbacks to your database.yml

<%= ENV['production_db'] || '""' %>  
coderanger
  • 52,400
  • 4
  • 52
  • 75