faber-lotto/capistrano-template

template can't see variables

Closed this issue · 2 comments

Why the template can't see the variables???

code:

set :unicorn_pid, -> { "#{fetch :shared_path}/tmp/pids/unicorn.pid" }
set :unicorn_config, -> { "#{fetch :shared_path}/config/unicorn.rb" }
set :unicorn_log, -> { "#{fetch :shared_path}/log/unicorn.log" }
set :unicorn_workers , 2

namespace :unicorn do
  desc "Setup Unicorn initializer and app configuration"
  task :setup do 
    on roles :app do
        execute :mkdir, "-p #{shared_path}/config"
        template "unicorn.rb.erb", "#{shared_path}/config/unicorn.rb", 0750
        template "unicorn_init.erb", "/tmp/unicorn_init", 0770
        execute :chmod, "+x /tmp/unicorn_init"
        #execute :sudo, "mv /tmp/unicorn_init /etc/init.d/unicorn_#{application}"
        #execute :sudo, "update-rc.d -f unicorn_#{application} defaults"
    end
  end
  after "deploy:started", "unicorn:setup"

  %w[start stop restart].each do |command|
    desc "#{command} unicorn"
    task command do
    on roles :app do
          execute :sudo, "service unicorn_#{:application} #{command}"
    end
    end
    after "nginx:#{command}", "unicorn:#{command}"
  end
end

output:

DEBUG [a70776ab] Finished in 0.182 seconds with exit status 0 (successful).
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deployer@server: undefined local variable or method 'unicorn_pid' for #<Capistrano::Template::Helpers::Renderer:0x007fd9845a8740>

You have to fetch them. Example:
fetch :unicorn_pid

set does not create a local variable and this gem does do any magic with the settings hash.

Feel free to reopen if it is a real bug.

thanks you were right