2017-02-20 6 views
1

私は生地を使用していると私は同時に別のホスト上で同時にファイルをダウンロードしたいが、私はファブリックrunコマンドは同時に

env.hosts = ['192.168.1.2', '192.168.1.3', '192.168.1.4']

を使用するとき、私はいつもNo hosts found. Please specify (single) host string for connection:

を取得します
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コードから実行します。

答えて

2

私は通常、@parallelデコレータ(http://docs.fabfile.org/en/1.13/usage/parallel.html)を使用して、このようなことを行います。

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 

そして、私はそれが工場の命令なしに私のコードで()私が代わりにenv.roledefsのenv.hostsを使用して、私が展開走った私を助けfab deploy:prod

+0

感謝を実行することができます。それは魔法のように働いた。 –

+0

うれしい、うれしかった! – davidejones

関連する問題