How To Make Fabric Execution Follow The Env.hosts List Order?
Solution 1:
The exact reason that the order is not preserved from env.hosts
is that there are three "levels" that the hosts to operate can be specified--env.hosts, the command line, and per function--which are merged together. In fabric/main.py
on line 309, you can see that they use the set()
type to remove duplicates in the three possible lists of hosts. Since set()
does not have an order, the hosts will be returned as a list in "random" order.
There's a pretty good reason that this is method. It's a very efficient mechanism for removing duplicates from a list and for fabric it's important that order doesn't matter. You're asking fabric to perform a series of completely parallel, atomic actions on various hosts. By the very nature of parallel, atomic actions, order does not effect the ability of the actions to be performed successfully. If order did matter, then a different strategy would be necessary and fabric would no longer be the correct tool for the job.
That said, is there a particular reason that you need these operations to occur in order? Perhaps if you're having some sort of problem that's a result of execution order, we can help you work that out.
Solution 2:
Just to update, newest Fabric 1.1+ (think even 1.0) dedupes in an order preserving way now. So this should be a non-issue now.
Post a Comment for "How To Make Fabric Execution Follow The Env.hosts List Order?"