试图从头开始测试 Capistrano。
头文件:
require 'capistrano/setup'
require 'capistrano/deploy'
I18n.enforce_available_locales = false
Dir.glob('lib/capistrano/tasks/*.rb').each { |r| import r }
部署.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
使用相同的用户和 key 从 shell 登录没有问题。
登录远程服务器时,我可以在 auth.log 中看到执行上限时给出的空用户:
test-srv sshd[1459]: Invalid user from x.x.x.x
我想念什么?
谢谢!
最佳答案
如果您查看在 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
关于ruby-on-rails - Capistrano 3 丢弃 :user variable when executing remote SSH command,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20455922/