【发布时间】:2025-12-05 03:50:02
【问题描述】:
为了使用带有 capistrano 的 erb 模板(无轨道),我按照 https://github.com/faber-lotto/capistrano-template 中给出的说明进行操作,但在运行 [bundle exec] cap staging define_usermacros -n --trace capistrano 时告诉我 SSHKit::Backend::Printer 不知道 template 方法:
** Invoke staging (first_time)
** Execute staging
** Invoke load:defaults (first_time)
** Execute load:defaults
** Invoke define_usermacros (first_time)
** Execute define_usermacros
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deploy@10.33.66.12: undefined method `template' for #<SSHKit::Backend::Printer:0x007ff383bd4d80>
/usr/local/var/rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/sshkit-1.13.1/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute'
/usr/local/var/rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/sshkit-1.13.1/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
NoMethodError: undefined method `template' for #<SSHKit::Backend::Printer:0x007ff383bd4d80>
config/deploy.rb:42:in `block (2 levels) in <top (required)>'
/usr/local/var/rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/sshkit-1.13.1/lib/sshkit/backends/abstract.rb:29:in `instance_exec'
/usr/local/var/rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/sshkit-1.13.1/lib/sshkit/backends/abstract.rb:29:in `run'
/usr/local/var/rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/sshkit-1.13.1/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
Tasks: TOP => define_usermacros
我尝试在捆绑包中升级和降级 capistrano、airbrush、sshkit,但无济于事,事情仍然失败。
目前 cap doctor 告诉我我正在使用以下版本:
环境
Ruby ruby 2.2.5p319 (2016-04-26 revision 54774) [x86_64-darwin15]
Rubygems 2.6.10
Bundler 1.14.3
Command /usr/local/var/rbenv/versions/2.2.5/bin/cap staging doctor
宝石
capistrano 3.7.2 (update available)
airbrussh 1.2.0
rake 12.0.0
sshkit 1.13.1
net-ssh 4.1.0
capistrano-template 0.0.8
这里是capistrano的东西:
宝石文件:
source "https://rubygems.org"
group :development do
gem "capistrano", "~> 3.7.0"
gem "capistrano-template"
end
Capfile:
require "capistrano/setup"
require "capistrano/deploy"
require "capistrano/scm/git"
install_plugin Capistrano::SCM::Git
require 'capistrano/capistrano_plugin_template'
配置/部署.rb:
[...]
desc 'Upload user macros as rendered erb-template'
task :define_usermacros do
on roles :all do
template 'resource.cfg', "#{release_path}/resource_file",
0o640,
locals: {
'user1' => 'blah'
}
end
end
...config/deploy/templates/shared/resource.cfg.erb中当然有erb模板。
欢迎提供有关解决方案或如何调试问题的任何提示!
【问题讨论】:
-
这似乎是您正在使用的 capistrano-template gem 中的一个错误。我建议在这里报告:github.com/faber-lotto/capistrano-template
-
这个错误应该在 gem 版本 0.0.9 中修复
标签: ruby templates capistrano erb sshkit