2013-12-08 46 views
4

嘗試從頭開始測試Capistrano。Capistrano 3丟棄:執行遠程SSH命令時的用戶變量

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' 

的test.rb任務:

namespace :test do 
desc "Uptime on servers" 
task :uptime do 
    on roles(:testrole) do 
    execute "uptime" 
    end 
end 
end 

帽命令:

cap production test:uptime 

輸出:

INFO [c077da7f] Running /usr/bin/env uptime on x.x.x.x 
DEBUG [c077da7f] Command: /usr/bin/env uptime 
cap aborted! 
Net::SSH::AuthenticationFailed 

不必須使用相同的用戶和鍵殼登錄的問題。 當登錄到遠程服務器上,我可以看到auth.log一個空的用戶在執行上限給出:

test-srv sshd[1459]: Invalid user from x.x.x.x 

我怎麼錯過? 謝謝!

+0

P.S. 'env.fetch(:user)'裏面的任務顯示正確的用戶 – Bigmyx

回答

9

如果你在他們的示例代碼來看看,提供當你cap install你的項目,你會看到這樣的事情在staging.rbproduction.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 

你會想在您指定用戶在其中一個位置,或使用fetch(:user)在運行時以編程方式抓取它。例如,

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

嗯,我很高興一些人最近發現這有幫助!也許@Bigmyx可以使它成爲公認的答案? – jeffbyrnes