Nuvi
Nuvi

Reputation: 687

parallel running in fabric python

I want to run a method on several remote hosts in parallel through Python script. I have their credential (ip,usr,pass). in order to do it I decorate the method with @parallel, and called it via execute() where I gave all hosts. my question is how do I set env.usr, env.password for each task? here is an example of my code:

class deployment()

    __init__():
        self.hosts = read_ips_from_csv

    def do_something(self)
       run(remote_command)

    def run_remote(self,func):
       execute(func,hosts = self.hosts) 

    def deploy(self):
       run_remote(self.do_something)

main():

my_deploy = deployment()
my_deploy.deploy()

the question is how to set the env parameters for each host in do_something()

thanks a lot for your answers!!

Upvotes: 0

Views: 568

Answers (2)

Nuvi
Nuvi

Reputation: 687

OK, so this is how i solve it (found it in another question https://stackoverflow.com/a/5568219/3216763 ): i added env.hosts and env password before calling the execute like this:

def run_remote(self,func):
    env.hosts = ['user1@host1:port1', '[email protected]']
    env.passwords = {'user1@host1:port1': 'password1', '[email protected]': 'password2'}
    execute(func)  

spent quite time on it so maybe it will help others.

Upvotes: 2

Oct
Oct

Reputation: 1525

  • At least for the login, this can be sent along with the hostname as explained in How to set target hosts in Fabric file.
  • I haven't found a simple way to do that for passwords. This is certainly monkey-patchable.

Note that the preferred way to do that is to use SSH keys with help you get rid of all this in a very simple way

Upvotes: 0

Related Questions