capistrano-template:未定义的方法`template'用于#<sshkit :: backend :: printer

时间:2017-06-08 13:54:42

标签: ruby templates capistrano erb sshkit

=“”

为了使用带有capistrano的erb模板(没有铁路)我按照https://github.com/faber-lotto/capistrano-template中的说明操作,但在运行[bundle exec] cap staging define_usermacros -n --trace时,卡门斯特拉诺告诉我template方法未知SSHKit::Backend::Printer

** 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

这是capistrano的东西:

的Gemfile:

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'

配置/ 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模板。

解决方案的任何提示或如何调试问题欢迎!

1 个答案:

答案 0 :(得分:0)

http://www.rubydoc.info/github/capistrano/sshkit/SSHKit/Backend/Printer用于干运行(即使用-n),因此在没有-n的情况下运行时工作正常。

干运行可以通过添加

来解决

SSHKit::Backend::Printer.send(:include, Capistrano::Template::Helpers::DSL)

之后

require 'capistrano/capistrano_plugin_template'

<{1>}中的