Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capistrano 3 discards :user variable when executing remote SSH command

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!

like image 963
Bigmyx Avatar asked Dec 16 '22 03:12

Bigmyx


1 Answers

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{[email protected]}
role :web, %w{[email protected]}
role :db,  %w{[email protected]}

# 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
like image 140
jeffbyrnes Avatar answered Dec 21 '22 17:12

jeffbyrnes