You can use the EC2 API to generate a list of hosts for you at runtime. This
is the same as working with any inventory system:

1) write a task or function to generate a list of hosts. For example, use
the EC2 API. You could even have it classify your hosts based on security
groups so they aren't all in one
bucket. I've found I need to stick this into a global array as I can't
call 'role' from inside of a task.
2) at the top of your Capfile, do something like:

task :GenerateHostList
  hosts = Hash.new

  // work magic with the EC2 API to populate hosts here

  set :ec2hosts, hosts
end

GenerateHostList

role :databases do
  ec2hosts['databases']
end

role :webservers do
  ec2hosts['webservers']
end


I've found the EC2 API's to be a bit slow when you're not on EC2, so I've
added a caching mechanism as well. I dump the hosts data structure to a file
and load that if it's found. I then delete the file when adding/removing
hosts.

On Thu, Jul 30, 2009 at 10:45 PM, johne <[email protected]> wrote:

>
> Having trouble trying to dynamically set host on a task at runtime.
> Basically I want to set the host dynamically when task is run.   I
> tried set with a block, but no luck.
>
> For example, I want this....
>
>  task :mount_ebs, :hosts => host do
>    sudo "mkdir /ebs1"
>    sudo "mount -t xfs /dev/sdh /ebs1"
>  end
>
> where host is dynamically generated at task run time....
>
> any help greatly appreciated
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Capistrano" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.co.uk/group/capistrano?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to