Reputation: 687
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
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
Reputation: 1525
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