2016-11-14 4 views
0

Ich habe zwei Server, auf denen ich bereitstellen muss, aber sie haben ein etwas anderes Setup. Die Anwendung wird auf jedem Server in einem anderen Pfad bereitgestellt (/var/www/sites/my_site und /var/www/my_site).python fabric put mit dynamischem remote_path

Meine Datei sieht etwa wie folgt aus:

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, ...) 

Antwort

1

Vielleicht können Sie Setup eine andere Variable mit den Pfaden und Schlüssel aus, dass aus dem aktuellen Host Sie sind. Etwas wie dieses

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)