--user=root似乎没有覆盖Fabric env.user,怎么来的?



我有一个带有的fabfile

env.user = 'deploy'
def infra():
    """You need to use a user that can root itself, deploy cannot without a
    password."""
    put('conf.d/etc/nginx/sites-available/www.foo.hk',
         '/etc/nginx/sites-available/www.foo.hk', use_sudo=True)
     sudo('nginx -s reload',)

我像fab infra -Rservers一样运行。

所以我想当我运行fab infra --user=root时,我可以用--user=root or -u root覆盖用户,但它仍然要求我输入密码。但是,如果我将env.user更改为env.user = 'root',则不会。我还可以使用设置上下文管理器,如:

def infra(user):
    """You need to use a user that can root itself, deploy cannot without a
    password."""
    with settings(user=user):
        put('conf.d/etc/nginx/sites-available/www.foo.hk',
             '/etc/nginx/sites-available/www.foo.hk', use_sudo=True)
        sudo('nginx -s reload',)

当我做fab infra:root -Rservers时,这很有效。很明显,可以覆盖设置,但从正常的命令行标志来看,我似乎无法覆盖。我做错什么了吗?

目前无法以我想要的方式从命令行覆盖默认设置。不过有张票https://github.com/fabric/fabric/issues/680而且它似乎会被修复。

您已经为此打开了一张门票,我还展示了与您在这里展示的更相似的示例。我的猜测是,你不能事先在文件中设置env.user,因为这是一个明确的硬编码。

我想您正在寻找:

fab infra:hosts=root@somehost

我不清楚相同的username@...模式是否适用于角色或角色定义。

http://docs.fabfile.org/en/1.2.0/usage/execution.html

最新更新