Capistrano deployment errors with database.yml

I’m trying to deploy using capistrano however I keep getting this database.yml not found error. My database.yml file is not commited to my repository and I’ve tried to set up my deploy.rb file to create a database.yml on the fly but it doesnt seem to be working. Here is my deploy.rb file:

require "bundler/capistrano"

set :application, ""
set :app_name, "myapp"
set :repository,  ""
set :scm, :git

server "", :web, :app, :db, primary: true

  set :user, "user" # As defined on your server
  set :password, "pwwd"
  set :deploy_to, "/var/www/html/" # Directory in which the deployment will take place
  set :mysql_user, 'root_user'
  set :mysql_password, 'root_pwwd'

set :deploy_via, :remote_cache
set :use_sudo, false
ssh_options[:forward_agent] = true

namespace :deploy do
  task :start do ; end
  task :stop do ; end
  task :restart, :roles => :app, :except => { :no_release => true } do
    run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"

namespace :deploy do  
  desc "Recreate symlink"
  task :resymlink, :roles => :app do
    run "#{try_sudo} rm -f #{current_path} && ln -s #{release_path} #{current_path}"


require 'erb'

before "deploy:setup", :db
after "deploy:update_code", "db:symlink"

namespace :db do
  desc "Create database yaml in shared path"
  task :default do
    db_config = <<-EOF
    base: &base
      adapter: mysql
      socket: /var/run/mysqld/mysql.sock
      username: #{mysql_user}
      password: #{mysql_password}

      database: #{app_name}_dev
      <<: *base

      database: #{app_name}_test
      <<: *base

      database: #{app_name}_prod
      <<: *base

    run "#{try_sudo} mkdir -p #{shared_path}/config"
    put db_config.result, "#{shared_path}/config/database.yml"

  desc "Make symlink for database yaml"
  task :symlink do
    run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"

after "deploy:create_symlink", "deploy:resymlink", "deploy:update_crontab"

Everytime I run cap deploy I get the following error after which deployment stops and rolls back.

  • Capistrano + Git : repository local to production server
  • run rails applicaton after capistrano deployment
  • What's the URL for rails app deployed by Capistrano
  • capistrano error: …/current: No such file or directory
  • Rails 3.1 and Asset Pipeline: Trouble on deploying with Capistrano
  • Rails 3 app, How to get GIT version and update website?
  • *** [err :: ] rake aborted!
    *** [err :: ] No such file or directory - /var/www/html/
    *** [err :: ] /var/www/html/ `read'

    Please help – I really need to get this done.

  • Heroku deployment failed because of sqlite3 gem error
  • getaddrinfo: nodename nor servname provided, or not known
  • Rails 4 asset pipeline losing vendor assets
  • Deploy subdirectory with mina
  • ActionView::MissingTemplate
  • Rails deployment - how do you do rake db:reset with capistrano?
  • One Solution collect form web for “Capistrano deployment errors with database.yml”

    You need to write to a file not just puts to stdout:

    Change this line:

    put db_config.result, “#{shared_path}/config/database.yml”

    to“#{shared_path}/config/database.yml”, “w”) { |f| f.puts db_config.result }

    Ruby is the best programming language in the world - Ruby on Rails.