On 2/20/08, Valerio Schiavoni <[EMAIL PROTECTED]> wrote:
>
> Also, another question about how to simply the definition of this
> role:
>
> role :peers, "ita10",
> "ita11" ,"ita12","ita13","ita19","ita21","ita26"...[the list go on...]
>
> can't I read the list of nodes from a file somehow ?


Short answer: yes, but probably not built-in.

Long answer: The Capfile, and config/deploy.rb if you're using that, are
valid Ruby. If that list is sequential, you can probably do something like:

(1..50).each do |i|
  role :peers, "ita#{i}"
end

If not, if you just wanted to not have it all on one line, you can do all
sorts of other fun syntax:

role :peers, 'ita10', 'ita12, 'ita13',
                   'ita19', 'ita21', 'ita26'

As long as the line ends in a comma, it's assumed that you'll continue on
the next line. The rest of the whitespace isn't significant, but I do think
it makes sense indented like that.

Or you could do automatic splitting into lists:

role :peers, *%W(ita10 ita12 ita13
                           ita19 ita21 ita26)

You can put that in a separate file, maybe called 'config/peers.rb', and put

require 'config/peers'

in your Capfile (or deploy.rb). Or you could write your own mechanism to
read it from a file. Here's one to read one line per host:

File.open 'some_file' do |file|
  file.each_line do |line|
    role :peers, line.chomp
  end
end

Keep in mind that all of this runs every time the "cap" command does, even
if you're just doing "cap -Tv". If you're feeling adventurous, I've got a
patch in SVN that changes it:

role :peers do
  servers = []
  File.open 'some_file' do |file|
    file.each_line do |line|
      servers << line.chomp
    end
  end
  servers
end

In this case, :peers is a lazy role -- it will only actually open the file
when you try to run some task that uses it.

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

Reply via email to