Lee is exactly right. But his syntax is a bit off. :)

  role(:app) { application_domain }

etc. If you need to set :primary => true on any of them, just return an array, where the last element of the array is a hash:

  role(:db) { [application_domain, { :primary => true }] }

Of course, the EASIEST solution is to just declare the roles in your stage file, instead of your primary deploy.rb. That's what we do. So, deploy.rb has no role declarations at all, and your stage.rb declares them instead.

- Jamis

On Nov 2, 2008, at 4:44 PM, Lee Hambley wrote:

Anthony,

This is an easy one, the problem is - not scope as you might think, but rather the order in which the files are loaded.

You can get this working, by using a Proc (more info) which will ensure that the block you assign isn't evaluated until you first use it... so this:
        • ./deploy.rb:
role :app, "#{application_domain}" #mongrel server
role :web, "#{application_domain}" #apache server "qa.example.net"
role :db,  "#{application_domain}", :primary => true #database server
(where migrations are run)
Becomes this:
        • ./deploy.rb:
role :app, { application_domain }     #mongrel server
role :web, { application_domain }    #apache server "qa.example.net"
role :db, { application_domain}, :primary => true #database server
(where migrations are run)
Note firstly, i've stopped them being an interpolated string - there's no point, unless it's part of a longer string, in this instance, it isn't - but more importantly they're being passed as a block (thus the {}) which is shorthand for a proc... it basically means that what you have assigned to :app is a mini-anonymous function that returns "application_domain" when you run (access) it.

-- Hope that helps, there's a little more reading, actually in the multistage faq, if memory serves - thogh you could be excused for having overlooked it :)

-- Lee H

2008/11/2 Anthony Ettinger <[EMAIL PROTECTED]>

I want to use a variable in deploy.rb that is defined in ./deploy/ stage.rb

./deploy.rb:
role :app, "#{application_domain}" #mongrel server
role :web, "#{application_domain}" #apache server "qa.example.net"
role :db,  "#{application_domain}", :primary => true #database server
(where migrations are run)

./deploy/stage.rb
set :application_domain, "#{application}" #example.com

./deploy/qa.rb
set rails_env, 'qa'
set :application_domain, "#{rails_env}.#{application}" #example.com


However variables defined in ./deploy/stage.rb files aren't accessible
from the general ./deploy.rb script.

--
Anthony Ettinger
408-656-2473
http://anthony.ettinger.name




--~--~---------~--~----~------------~-------~--~----~
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/capistrano
-~----------~----~----~----~------~----~------~--~---


Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to