ruby-on-rails - Capistrano 3 丢弃 :user variable when executing remote SSH command

标签 ruby-on-rails ssh capistrano

试图从头开始测试 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.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{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/

相关文章:

ruby-on-rails - MongoMapper(或任何其他 Mongodb 适配器)是否有类似 "accepts_nested_attributes_for"的方法?

ruby-on-rails - 国家/地区的下拉菜单

ruby-on-rails - 路由无法正常工作

git - pull git repo 时如何设置 ssh key ?

macos - 在 Mac OSx 上通过 SSH 连接到 EC2 时出现权限错误

ruby-on-rails - "bash: bundle: command not found"- 上限中止

deployment - 使用 capistrano 部署一次特定分支?

ruby - Capistrano 登录 Net::SSH 失败

ruby-on-rails - 在路由规范中指定默认格式

python - 通过 ssh 连接在 Cuda 设备上使用 NumbaPro