We’ve been using Fabric to set up and build Gelato on AWS. Each time I use it I’m left with this sense of awe at how amazing it is. Going from having to manually SSH into each machine to do anything to have Fabric build your code on 15 machines in parallel is indescribable.
One thing that we were having trouble with was having Fabric run a task on specific host roles in parallel. To run tasks in parallel you use the @parallel decorator, while to run tasks on hosts by roles you use the @roles decorator. If you want to run tasks in parallel on specific hosts you have to be careful of the order in which you apply these decorators. Here is what worked for us:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
… | |
env.roledefs = { | |
"service_A": ["hostA1", "hostA2", …], | |
"service_B": ["hostB1", "hostB2", …], | |
"service_C": ["hostC1", "hostC2", …], | |
… | |
} | |
@task | |
@parallel | |
@roles("service_A", "service_B", "service_C") | |
def build(): | |
… |
P.S. make sure you set the correct Bubble Size if you have a large number of hosts!