我想通过Python脚本在多个远程主机上并行运行一个方法。 我有他们的证件(ip,usr,pass)。 为了做到这一点,我用@parallel
来装饰方法,并通过在那里给所有主机。 我的问题是如何为每个任务设置env.usr
,env.password
? 这里是我的代码示例:并行运行在结构python
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()
的问题是如何设置每个主机的env
参数do_something()
非常感谢您的回答!
请注意,首选方法是使用SSH密钥,以帮助您以非常简单的方式摆脱所有这些情况。你能澄清吗? – Nuvi
SSH密钥允许您使用您决定的相同密码登录多个受密码保护的ssh帐户。 ssh密钥的使用归结为生成一个ssh密钥,将其公共版本放在每个服务器上,并将'env.key_filename =“〜/ .ssh/id_rsa”'添加到你的fabfile中。有关ssh密钥的更多信息,Google是你的朋友(这个盒子对于这样的讨论感觉太小了))... – Oct
谢谢!我这次解决了它,但一定会看你的建议。 – Nuvi