Fabric:为每个主机外部任务设置配置变量

时间:2012-09-15 19:07:48

标签: python deployment fabric

此问题类似于 - Pass parameter to fabric task

我的问题是我想将sphinx html documentation部署到remote server

我还想定义一个远程目录,我将文件复制到每个主机,分别在任务函数之外,最好也在fabfile之外。

1 个答案:

答案 0 :(得分:1)

如果主机和路径提前知道或可以计算,请使用字典。 EG:

env.sphinx_path = {
    'hosta': 'patha',
    'hostb': 'pathb',
}

@task
@hosts('hosta','hostb')
def foo(dummy_var):
    put('sphinx_stuff', env.sphinx_path%env.host)

否则你可以像以下一样传递路径:

fab foo:'sphinx/path'

这将填充上面示例中的dummy_var,然后在任务中使用。