faber-lotto/capistrano-template

NameError: undefined local variable or method `host' for main:Capistrano::Template::Helpers::PathsLookup

Closed this issue · 5 comments

Hi,

I have a plain ruby project and with and I get the following error:

/Users/ap/.rvm/gems/ruby-2.1.2/bundler/gems/capistrano-template-d0c6d3e11396/lib/capistrano/template/helpers/paths_lookup.rb:26:in `block in paths_for_file'
/Users/ap/.rvm/gems/ruby-2.1.2/bundler/gems/capistrano-template-d0c6d3e11396/lib/capistrano/template/helpers/paths_lookup.rb:25:in `map'
/Users/ap/.rvm/gems/ruby-2.1.2/bundler/gems/capistrano-template-d0c6d3e11396/lib/capistrano/template/helpers/paths_lookup.rb:25:in `paths_for_file'
/Users/ap/.rvm/gems/ruby-2.1.2/bundler/gems/capistrano-template-d0c6d3e11396/lib/capistrano/template/helpers/paths_lookup.rb:17:in `template_file'
/Users/ap/.rvm/gems/ruby-2.1.2/bundler/gems/capistrano-template-d0c6d3e11396/lib/capistrano/template/helpers/paths_lookup.rb:13:in `template_exists?'
/Users/ap/.rvm/gems/ruby-2.1.2/bundler/gems/capistrano-template-d0c6d3e11396/lib/capistrano/template/helpers/dsl.rb:23:in `template_exists?'
/Users/ap/.rvm/gems/ruby-2.1.2/bundler/gems/capistrano-template-d0c6d3e11396/lib/capistrano/template/helpers/dsl.rb:6:in `template'
config/deploy.rb:51:in `block (2 levels) in <top (required)>'
/Users/ap/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/task.rb:240:in `call'
/Users/ap/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/task.rb:240:in `block in execute'
/Users/ap/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/task.rb:235:in `each'
/Users/ap/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/task.rb:235:in `execute'
/Users/ap/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/Users/ap/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/Users/ap/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
/Users/ap/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/task.rb:165:in `invoke'
/Users/ap/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/application.rb:150:in `invoke_task'
/Users/ap/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/Users/ap/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/application.rb:106:in `each'
/Users/ap/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/application.rb:106:in `block in top_level'
/Users/ap/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/application.rb:115:in `run_with_threads'
/Users/ap/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/application.rb:100:in `top_level'
/Users/ap/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/application.rb:78:in `block in run'
/Users/ap/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/application.rb:176:in `standard_exception_handling'
/Users/ap/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/application.rb:75:in `run'
/Users/ap/.rvm/gems/ruby-2.1.2/gems/capistrano-3.2.1/lib/capistrano/application.rb:15:in `run'
/Users/ap/.rvm/gems/ruby-2.1.2/gems/capistrano-3.2.1/bin/cap:3:in `<top (required)>'
/Users/ap/.rvm/gems/ruby-2.1.2/bin/cap:23:in `load'
/Users/ap/.rvm/gems/ruby-2.1.2/bin/cap:23:in `<main>'
/Users/ap/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `eval'
/Users/ap/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `<main>'

My Gemfile looks like this:

source 'https://rubygems.org'

gem 'capistrano', "> 3.0"
gem 'capistrano-template', :git => "git@github.com:faber-lotto/capistrano-template.git"

An my Capfile like this:

# Load DSL and Setup Up Stages
require 'capistrano/setup'

# Includes default deployment tasks
require 'capistrano/deploy'
require 'capistrano/capistrano_plugin_template'

# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }

Finally this is the task that I try to run:

namespace :nginx do
  task :upload_app_conf do
    template 'nginx.app.conf'
  end
end

I have no clue where the host method/attribute should come from.
Do I need to set it, or am I missing an dependency?

Best,
Gerwin

host ist defined within SSHKit::Backend::Abstract. It comes through the SSHKit::DSL => Coordinator.new(hosts) and so on ...

An now I see your issue. template works only wihtin an on block.

on roles :all do
    template 'assets.host.site'
end

Oh...
That could have been obvious. Works now :)

Thanks for the awesome fast answer!

You'r welcome. When you run into scoping issues try https://github.com/faber-lotto/sshkit-custom-dsl

sshaw commented

Ran into this problem. You should raise an exception or warn so that the user knows that they need to put template in an on block.

Seeing:

NameError: undefined local variable or method `host' for main:Capistrano::Template::Helpers::PathsLookup

gives one the impression that the code is broken (well, it is :neckbeard:).

Well, you'r right. Maybe it will be done some day. At the moment I it seems like this gem is not maintained.