title: Run multiple commands one host at a time
body: <p>The environment I'm running in requires that the server be stopped before web application files can be copied over. So I'd like to perform the following set of tasks using fabric:</p>
  
  <ol>
  <li>stop server</li>
  <li>copy over new files</li>
  <li>restart server</li>
  </ol>
  
  <p>If I want to deploy to 20 hosts and I do something like this...</p>
  
  <pre><code>def deploy:
    run("server stop")
    run("rsync ...")
    run("server start")
  </code></pre>
  
  <p>...there will be unnecessary downtime as every single server is first brought down, then files are sync'd to all servers, and finally all servers are brought back up. This stems from the fact that the "run" command is executed on each host.</p>
  
  <p>Is there an elegant way to have multiple commands run on each host? This is a naive stab at what I'm looking for:</p>
  
  <pre><code>for host in env.hosts
     env.host = host
     run("server stop")
     run("rsync ...")
     run("server start")
  </code></pre>
  
  <p>I did see that there is the ability to have "run" commands occur in parallel but thats not exactly what I'm looking for.</p>