Capistrano 3 discards :user variable when executing remote SSH command

capistrano, ruby-on-rails, ssh

Solution

If you take a look at their example code, supplied when you `cap install` your project, you'll see something like this in `staging.rb` and `production.rb`:

# Simple Role Syntax
# ==================
# Supports bulk-adding hosts to roles, the primary
# server in each group is considered to be the first
# unless any hosts have the primary property set.
# Don't declare `role :all`, it's a meta role
role :app, %w{deploy@example.com}
role :web, %w{deploy@example.com}
role :db,  %w{deploy@example.com}

# Extended Server Syntax
# ======================
# This can be used to drop a more detailed server
# definition into the server list. The second argument
# something that quacks like a hash can be used to set
# extended properties on the server.
server 'example.com', user: 'deploy', roles: %w{web app}, my_property: :my_value

You'll either want to specify your user in one of those places, or use `fetch(:user)` to grab it programmatically at runtime. E.g.,

server 'example.com', user: fetch(:user), roles: %w{web app}, my_property: :my_value

Problem

Trying to test Capistrano from scratch. Capfile: ``` require 'capistrano/setup' require 'capistrano/deploy' I18n.enforce_available_locales = false Dir.glob('lib/capistrano/tasks/*.rb').each { |r| import r } ``` deploy.rb: ``` role :testrole, 'x.x.x.x' set :user, 'ubuntu' ``` The test.rb task: ``` namespace :test do desc "Uptime on servers" task :uptime do on roles(:testrole) do execute "uptime" end end end ``` cap command: ``` cap production test:uptime ``` output: ``` INFO [c077da7f] Running /usr/bin/env uptime on x.x.x.x DEBUG [c077da7f] Command: /usr/bin/env uptime cap aborted! Net::SSH::AuthenticationFailed ``` Dont have a problem to login from the shell using the same user and key. While logged in the remote server, I can see in auth.log that an empty user given while executing the cap: ``` test-srv sshd[1459]: Invalid user from x.x.x.x ``` What do I miss ? Thanks!

Original source