Chad, Excellent work, would you consider adding that to the wiki at capify.org?
-- Lee Hambley Twitter: @leehambley Blog: http://lee.hambley.name/ Working with Rails: http://is.gd/1s5W1 2009/8/3 Chad Arimura <[email protected]> > > > > I combined Gary's solution above with a fork of the RightAWS library > (http://github.com/appoxy/aws/tree/master) to loop over a > describe_instance call until the status of the launched server is > "Running". You can then return the public dns (or whatever > information you need). > > > > desc "Launch one new instance" > task :run_instance do > @ec2 = RightAws::Ec2.new(AWS_ACCESS_KEY, AWS_SECRET_KEY) > > @ret = @ec2.launch_instances(AMI_ID, > :addressing_type => "public", > :group_ids => SECURITY_GROUPS, > :key_name => KEYNAME, > :availability_zone => AVAIL_ZONE) > puts "Launched Instance: " + @ret[0][:aws_instance_id].to_s > puts "Server is launching, should take about 2 minutes." > > tries = 0 > begin > @instance_info = @ec2.describe_instances([...@ret[0] > [:aws_instance_id]]) > raise StandardError, "Pending...." unless @instance_info > [0][:aws_state] == "running" > > puts "Server Launched!\n" > puts "Availability Zone: #...@instance_info[0][:aws_state]}" > puts "Public DNS: #...@instance_info[0][:dns_name]} \n\n" > set :ec2host, @instance_info[0][:dns_name] > > puts "Waiting 10 seconds for server's SSH to start......." > sleep 10 > rescue > puts ". " > sleep 3 > tries += 1 > retry unless tries == 100 > puts "We did not see the server start within 3 minutes. > Please check AWS console for actual information." > end > end > > > Hope this is also helpful in some way. > > > -- > Chad > http://blog.appoxy.com > > > > > > > On Aug 1, 7:37 am, Gary Richardson <[email protected]> wrote: > > 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 -~----------~----~----~----~------~----~------~--~---
