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.

  • require file from gem
  • What port to use sending email with SMTP (mailgun) in rails app on production server (DigitalOcean)?
  • How to install capistrano v2.13.5 with ruby 1.8.7?
  • rails active admin deployment : couldn't find file 'jquery-ui'
  • Capistrano 3 SSHKit::Runner::ExecuteError: Exception while executing on host agent could not sign data with requested identity
  • How to build task 'gems:install'
  • *** [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.

  • Excluding files from being deployed with Capistrano while still under version control with Git
  • Starting background tasks with Capistrano
  • Installing capistrano on Ubuntu
  • How can I deploy 'private' gems that my apps can access but no one else can get?
  • Rails Error: NoMethodError: undefined method `instance' for Capistrano::Configuration:Class Did you mean? instance_of?
  • How to deploy an RubyGem-based Server
  • 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.