尝试从头开始测试Capistrano。
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命令:
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
使用相同的用户和密钥从shell登录时没有问题。 登录远程服务器后,我可以在auth.log中看到执行上限时给出一个空用户:
test-srv sshd[1459]: Invalid user from x.x.x.x
我想念什么? 谢谢!
答案 0 :(得分:12)
如果您查看项目cap install
时提供的示例代码,您会在staging.rb
和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
您要么在其中一个位置指定您的用户,要么使用fetch(:user)
在运行时以编程方式获取它。如,
server 'example.com', user: fetch(:user), roles: %w{web app}, my_property: :my_value