I am trying to use fabric 2.3 to run few tasks that require sudo on some servers . My main goal here was to parallelize the operation so i thought of using ThreadingGroup
class of fabric api however it does not support sudo
.
Below is my code for sake of clarity
#!/usr/bin/env python
from fabric import ThreadingGroup, Config
from getpass import getpass
sudo_pass = getpass("Enter your sudo password: ")
sudo_config = Config(overrides={'sudo': {'password': sudo_pass}})
server_pool = ThreadingGroup("test1", "test2",
config=sudo_config)
result = server_pool.sudo('cat /etc/shadow', hide='stderr')
print(result)
Now this does not work as mentioned above because ThreadingGroup
does not support all of the methods that Connection
class support.
I can run sudo
on multiple servers by iterating over the individual hosts and then creating connection for each but that isn't efficient.
So is there a way to make this parallel with fabric 2.3 ? I have gone through the official documentation as well but did not find anything.
Further i did some more testing on it following the official documentation and it seems like ThreadingGroup
achieves parallelism only if you run it like below
fabric.ThreadingGroup('test1', 'test2').run('uname -s')
however if you run it like below it does not run in parallel
def run_task(c):
c.run('uname -s')
for cxn in fabric.ThreadingGroup('test1', 'test2'):
run_task(cxn)
So it looks like there isn't much flexible support for parallelism in fabric 2.3 as of now and i might have to switch back to fabric version 1 only.