2016-11-14 94 views
0

我有兩個服務器,我需要部署到,但他們有一個稍微不同的設置。該應用程序被部署到每個服務器上的不同路徑(/var/www/sites/my_site/var/www/my_site)。蟒蛇織物與動態remote_path

我的文件看起來有點像這樣:

env.roledefs = { 
    'production': ['host1.foo.bar', 'host2.foo.bar'] 
} 

@task 
@roles(['production']) 
def deploy(): 
    files = getBundlePaths() 

    for file in files: 
     # How would I go about uploading to a different path per server? 
     put(file, ...) 

回答

1

也許你可以設置與當前主機你在路徑和鍵關機另一個變量。像這樣的東西

from fabric.api import * 

env.roledefs = { 
    'production': ['host1.foo.bar', 'host2.foo.bar'] 
} 

env.paths = { 
    'production': { 
     'host1.foo.bar': '/var/www/sites/my_site', 
     'host2.foo.bar': '/var/www/my_site' 
    } 
} 

@task 
@roles(['production']) 
def deploy(): 
    files = getBundlePaths() 

    path = env.paths[env.effective_roles[0]][env.host] 
    print(path) 

    for file in files: 
     put(file, path)