python 布料动态放置 remote_path
python fabric put with dynamic remote_path
我有两台服务器需要部署,但它们的设置略有不同。应用程序部署到每台服务器上的不同路径(/var/www/sites/my_site
和 /var/www/my_site
)。
我的文件看起来像这样:
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, ...)
也许您可以使用路径设置另一个变量,并从您所在的当前主机关闭该变量。像这样
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)
我有两台服务器需要部署,但它们的设置略有不同。应用程序部署到每台服务器上的不同路径(/var/www/sites/my_site
和 /var/www/my_site
)。
我的文件看起来像这样:
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, ...)
也许您可以使用路径设置另一个变量,并从您所在的当前主机关闭该变量。像这样
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)