为了将erb模板与capistrano一起使用(无轨道(,我按照 https://github.com/faber-lotto/capistrano-template 中给出的说明进行操作,但是当运行[bundle exec] cap staging define_usermacros -n --trace
capistrano时,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,airbrussh,sshkit,但无济于事,事情仍然破碎。
目前,帽医生告诉我我正在使用以下版本:
环境
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
这是卡皮斯特拉诺的东西:
宝石文件:
source "https://rubygems.org"
group :development do
gem "capistrano", "~> 3.7.0"
gem "capistrano-template"
end
封盖文件:
require "capistrano/setup"
require "capistrano/deploy"
require "capistrano/scm/git"
install_plugin Capistrano::SCM::Git
require 'capistrano/capistrano_plugin_template'
config/deploy.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模板。
欢迎提供有关解决方案或如何调试问题的任何提示!
试运行(即使用 -n(,因此作业在没有 -n 的情况下运行时有效。
通过添加来固定的干运行
SSHKit::Backend::Printer.send(:include, Capistrano::Template::Helpers::DSL)
后
require 'capistrano/capistrano_plugin_template'
在Capfile
.