this is my first attempt to deploy a Rails app using Capistrano. I am following the tutorial at https://ogdenstudios.xyz/blog/how-do-i-deploy-a-rails-6-app-to-amazon-ec-2/ to deploy to an AWS EC2 instance. My app is on Rails 6 and runs smoothly on localhost. I followed the tutorial but I am stock in the final step, when i run cap production deploy
y get the following error:
00:00 rbenv:validate
rbenv: rbenv_ruby is not set; ruby version will be defined by the remote hosts via rbenv
00:00 git:wrapper
01 mkdir -p /tmp
#<Thread:0x00007fd74423aa28 /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
12: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
11: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:31:in `run'
10: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:31:in `instance_exec'
9: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/capistrano-3.14.1/lib/capistrano/scm/tasks/git.rake:8:in `block (3 levels) in eval_rakefile'
8: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:80:in `execute'
7: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:148:in `create_command_and_execute'
6: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:148:in `tap'
5: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:148:in `block in create_command_and_execute'
4: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/backends/netssh.rb:130:in `execute_command'
3: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/backends/netssh.rb:177:in `with_ssh'
2: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/backends/connection_pool.rb:63:in `with'
1: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/backends/connection_pool.rb:63:in `call'
/Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/net-ssh-6.1.0/lib/net/ssh.rb:268:in `start': Authentication failed for user ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com (Net::SSH::AuthenticationFailed)
1: from /Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
/Users/bobsled/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com: Authentication failed for user ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com (SSHKit::Runner::ExecuteError)
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com: Authentication failed for user ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com
Caused by:
Net::SSH::AuthenticationFailed: Authentication failed for user ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com
Tasks: TOP => deploy:check => git:check => git:wrapper
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com: Authentication failed for user ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com
** DEPLOY FAILED
** Refer to log/capistrano.log for details. Here are the last 20 lines:
INFO [7f1cf201] Running /usr/bin/env mkdir -p /tmp as ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com
DEBUG [7f1cf201] Command: ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="" ; /usr/bin/env mkdir -p /tmp )
INFO ---------------------------------------------------------------------------
INFO START 2020-08-07 13:31:07 -0500 cap production deploy
INFO ---------------------------------------------------------------------------
INFO rbenv: rbenv_ruby is not set; ruby version will be defined by the remote hosts via rbenv
INFO [0bfcc93b] Running /usr/bin/env mkdir -p /tmp as ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com
DEBUG [0bfcc93b] Command: ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="" ; /usr/bin/env mkdir -p /tmp )
INFO ---------------------------------------------------------------------------
INFO START 2020-08-07 13:50:22 -0500 cap production deploy
INFO ---------------------------------------------------------------------------
INFO rbenv: rbenv_ruby is not set; ruby version will be defined by the remote hosts via rbenv
INFO [cb1eb774] Running /usr/bin/env mkdir -p /tmp as ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com
DEBUG [cb1eb774] Command: ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="" ; /usr/bin/env mkdir -p /tmp )
INFO ---------------------------------------------------------------------------
INFO START 2020-08-07 14:09:05 -0500 cap production deploy
INFO ---------------------------------------------------------------------------
INFO rbenv: rbenv_ruby is not set; ruby version will be defined by the remote hosts via rbenv
INFO [86bd8328] Running /usr/bin/env mkdir -p /tmp as ubuntu@ec2-13-59-204-151.us-east-2.compute.amazonaws.com
DEBUG [86bd8328] Command: ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="" ; /usr/bin/env mkdir -p /tmp )
I am adding my deploy.rb file
# config valid for current version and patch releases of Capistrano
lock "~> 3.14.1"
set :application, "lantiamaster"
set :repo_url, "git@github.com:Robs-v82/lantiamaster.git"
# Default branch is :master
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp
# Default deploy_to directory is /var/www/my_app_name
set :deploy_to, "/home/ubuntu/lantiamaster"
set :use_sudo, true
set :branch, 'master'
# Default value for :format is :airbrussh.
# set :format, :airbrussh
# You can configure the Airbrussh format using :format_options.
# These are the defaults.
# set :format_options, command_output: true, log_file: "log/capistrano.log", color: :auto, truncate: :auto
# Default value for :pty is false
set :pty, true
set :ssh_options, {
forward_agent: true,
user: fetch(:user),
# auth_methods: %w[publickey],
keys: %w[~/server-keys/lantiamaster-key-pair.pem]
}
# Default value for :linked_files is []
# append :linked_files, "config/database.yml"
set :linked_files, %w{config/master.key}
# Default value for linked_dirs is []
# append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "public/system"
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system')
# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
# Default value for local_user is ENV['USER']
# set :local_user, -> { `git config user.name`.chomp }
# Default value for keep_releases is 5
# set :keep_releases, 5
# Uncomment the following to require manually verifying the host key before first deploy.
# set :ssh_options, verify_host_key: :secure
I am new to deployment and I have no clue about what the problem could be. I created SSH keys, which I saved in both, my ubuntu virtual machine, and my Github account.
AWS ec2 instance require pem key to connect to it, so you must tell capistrano what key is use, I think you need add this config to your deploy file:
set :ssh_options, { forward_agent: true, user: fetch(:user), keys: path_to_pem_key }