2014-02-21 35 views
0

我使用Python 2.6/Fabric 1.8.0,並且我有幾個主機包含不同的本地路徑和變量。如何針對結構中的主機列表運行任務

import 
.... 

def vmm_two_a(): 
    env.hosts = 'xxx.xx.xx.xx' 
    env.user = 'tom' 
    env.password = password_from_netrc(env.hosts,env.user) 
    global local_path 
    local_path = '/home/vmm_two_a/binaries' 

def vmm_two_mgmt(): 
    env.hosts = 'xxx.xx.xx.xx' 
    env.user = 'john' 
    env.password = password_from_netrc(env.hosts,env.user) 
    global local_path 
    local_path = '/home/vmm_two_mgmt/binaries' 


def get_etc_binaries(): 
''' Get all etc binaries deployed ''' 
with hide('stderr','stdout','output','running', 'warnings'): 
    settings(warn_only=True) 
    get('/usr/local/etc', local_path) 

如何針對所有主機運行此任務?我試過fab -H沒有成功。

感謝您的幫助

回答

0

在這種情況下你需要調用任務設置ENV每次get_etc_binaries任務之前瓦爾。你也可以讓local_path成爲env.local_path,所以它更容易共享。

這樣的調用看起來像:fab vmm_twomgmt get_etc_binaries vmm_two_a get_etc_binaries

相關問題