Python 结构同时在不同主机上运行命令
我正在使用fabric,我想同时在不同的主机上下载一个文件,但是当我使用Python 结构同时在不同主机上运行命令,python,fabric,Python,Fabric,我正在使用fabric,我想同时在不同的主机上下载一个文件,但是当我使用 env.hosts=['192.168.1.2','192.168.1.3','192.168.1.4'] 我总是找不到主机。请为连接指定(单个)主机字符串: from fabric.api import env , run, sudo, settings env.user = 'root' #all the servers have the same username env.hosts = ['192.168.1.2
env.hosts=['192.168.1.2','192.168.1.3','192.168.1.4']
我总是找不到主机。请为连接指定(单个)主机字符串:
from fabric.api import env , run, sudo, settings
env.user = 'root' #all the servers have the same username
env.hosts = ['192.168.1.2', '192.168.1.3', '192.168.1.4']
env.key_filename = "~/.ssh/id_rsa" # I have their ssh key
run('wget file') #The command I need to run in parrallel
我想在不使用fab命令的情况下从python代码中运行它。我通常使用@parallel decorator()并执行类似的操作
env.use_ssh_config = True
env.user = 'ubuntu'
env.sudo_user = 'ubuntu'
env.roledefs = {
'uat': ['website_uat'],
'prod': ['website01', 'website02']
}
@task
def deploy(role_from_arg, **kwargs):
# on each remote download file
execute(download_file, role=role_from_arg, **kwargs)
@parallel
def download_file(*args, **kwargs):
# some code to download file here
然后我可以运行
fab deploy:prod
,感谢它帮助我使用env.hosts而不是env.roledefs,并且我在代码中运行deploy(),而不使用fab命令。它工作起来很神奇。:prod
做什么?@slimtabka:你能发布你的代码(为你工作的那一个)吗?嗨,我真的很抱歉,我再也不能访问代码了。我以前的工作就是这样的:prod我不知道它做什么,因为我直接使用了python的fabric,而不是fab命令@pg2455 prod是指运行任务部署,但使用名为prod的roledef,其中列出了2台服务器。这意味着它将连接到website01并运行download_文件,然后连接到website02并运行download_文件。