Hi,

This appears to have done the trick:


task :test_cycle do
        transaction do
                $servers = IO.readlines(server_list)            # Get the list 
of servers from
temp file.
                $servers.each {|$server|
                        $server.chomp
                        role :servers_each, $server
                        puts "Sleeping for #{sleepy} seconds"
                        sleep sleepy                                         # 
Allow a
pause between servers
                        task1                                   # Run task 1
                        task2                                   # Run second 
task
                        roles[:servers_each].clear              # Reset 
:servers_each array
                }
    end
end



task :task1, :roles => :servers_each do
        run "uptime"
end


task :task2, :roles => :servers_each do
        run "cat /etc/resolv.conf"
end


Thanks for your help with this Jamis.




On Jun 11, 5:08 pm, JasonSmithy <[EMAIL PROTECTED]> wrote:
> Hi,
>
> Unfortunately, the max_hosts option does not work for me because I
> need to run a whole transaction for the group before moving to the
> next one. Max_hosts currently runs each command and then gets the next
> "slice" of servers. My original post does what is needed except that
> it continues to add servers during each iteration of the while loop. I
> think all that I need to do is toreset:servers_each back to not
> having any servers. The only way I have been able to modify the value
> stored in :servers_each is to replace:
>                      role:servers_each, servers_each.clear (this
> causes an error BTW. I forgot to take it out of the code in my post)
>
> from my original post with:
>
>                role:servers_each do
>                         roles[:servers_each].clear
>                 end
>
> But, this yields:
>
> One succesful run on one server and then:
> 'test_each' is only run for servers matching {:roles=>:servers_each},
> but no servers matched
>
> It looks like the .clear is working, but I do not understand
> why :servers_each does not getresetto $ip when the while loop runs
> again.
>
> I looked at therole.rb and roles.rb files, but am not sure what to do
> with them.  Can someone please tell me what I doing wrong or give me
> some pointers?
>
> Thank you!
>
> On Jun 11, 10:24 am, JasonSmithy <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hi Jamis,
>
> > Thanks for your help!
>
> > For now I have just put a sleep statement in capistrano/configuration/
> > connections.rb after:
>
> >         servers.each_slice(max_hosts) do |servers_slice|
> >           begin
> >             establish_connections_to(servers_slice)
> >             sleep 30
>
> > That should work for me for now. I am new to ruby, but if I figure out
> > how to get this to work "properly", I will submit a patch.
>
> > Thanks for all your hard work on this project!
>
> > On Jun 10, 1:21 pm, Jamis Buck <[EMAIL PROTECTED]> wrote:
>
> > > No worries, it's really my fault for the abysmal lack of  
> > > documentation. Currently, the source code is the documentation,  
> > > meaning that if you want to know what options are available, you have  
> > > to go spelunking through the code. :(
>
> > > Regarding a wait time for max_hosts, do you mean, a delay before the  
> > > next set of hosts is used? There is currently no delay between runs,  
> > > but that might make a good patch. The code in question is in  
> > > capistrano/configuration/connections.rb, just search for :max_hosts.
>
> > > - Jamis
>
> > > On Jun 10, 2008, at 1:24 PM, JasonSmithy wrote:
>
> > > > Thank you Jamis!
>
> > > > Please forgive my ignorance, but how can I know what other options
> > > > like :max_hosts are available? And is there a way to configure the
> > > > time that max_hosts waits? I have not had any luck finding it in the
> > > > source yet.
>
> > > > Thanks again!
>
> > > > On Jun 9, 9:16 pm, Jamis Buck <[EMAIL PROTECTED]> wrote:
> > > >> Actually, capistrano has that functionality baked in, via  
> > > >> the :max_hosts
> > > >> option. You could define yourrolewith a block, so it gets evaluated
> > > >> late (from a temp file, for example), and then just set  
> > > >> the :max_hosts
> > > >> option on the task in question. E.g.:
>
> > > >>  role:dynamic_servers do
> > > >>     IO.readlines(server_list).map { |line| line.chomp }
> > > >>   end
>
> > > >>   desc "Test cycling through servers"
> > > >>   task :test_each, :roles => :dynamic_servers, :max_hosts => 5 do
> > > >>     run "uptime"
> > > >>   end
>
> > > >> Then, when capistrano is asked to execute the "uptime" command on all
> > > >> servers in the dynamic_serversrole, it will first evaluate the block
> > > >> for the dynamic_serversrole, and will then see that it is only to  
> > > >> use 5
> > > >> hosts at a time.
>
> > > >> - Jamis
>
> > > >> JasonSmithy wrote:
> > > >>> Hi,
>
> > > >>> Is there anyway toresetarole?
>
> > > >>> What I want to do is read a list of IPs dynamically from a temporary
> > > >>> file, then run a task on a portion of the list at a time, not have  
> > > >>> the
> > > >>> task run on all the IP's directly in parallel. What I am trying to  
> > > >>> do
> > > >>> so far is to get the list, run the task on the first IP in the list,
> > > >>> sleep for 5 seconds and then run the task again on the next IP in  
> > > >>> the
> > > >>> list. Ideally, this would take 5 IPs at a time until all IPs are
> > > >>> executed, but I need to learn to crawl before I can walk ;)
>
> > > >>> task :test_cycle do
> > > >>>    transaction do
> > > >>>            set :j, 4
> > > >>>            set :k, 0
> > > >>>            $servers = IO.readlines(server_list)    # Get the list  
> > > >>> of servers from
> > > >>> temp file.
> > > >>>            while k < j
> > > >>>                            # This is a method to increment by one.  
> > > >>> Capistrano
> > > >>>                            # complains that "+" is an unknown  
> > > >>> method without this.
> > > >>>                def add(value)
> > > >>>                    value = value + 1
> > > >>>                    return value
> > > >>>                end
>
> > > >>>                $ip = $servers[k].chomp
>
> > > >>>                            role:servers_each, $ip                
> > > >>> # Set the
> > > >>> server_eachroleto the new IP
>
> > > >>>                             test_each                      # Run  
> > > >>> the task
> > > >>>                    set :k, add(k)                  # Increment k  
> > > >>> by 1.
> > > >>>                            role:servers_each, servers_each.clear
> > > >>>                        end
> > > >>>             end
> > > >>> end
>
> > > >>> desc "Test cycling through servers"
> > > >>> task :test_each, :roles => :servers_each do
> > > >>>    run "uptime"
> > > >>>    puts "Sleeping for 5 seconds"
> > > >>>    sleep 5
> > > >>> end
>
> > > >>> This works except for each time the loop is run, the next IP gets
> > > >>> added to the server_eachrole. This has the effect of re-running the
> > > >>> command on each server each time. So the first time it runs from 1
> > > >>> server. The next time, it runs on 2 servers, and so on.
>
> > > >>> How can I set server_each back to empty after running test_each  
> > > >>> and is
> > > >>> this even the a good way to do this?
>
> > > >>> Thanks in advance for you help!
--~--~---------~--~----~------------~-------~--~----~
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