3

我有一个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

--user=root or -u root所以我想我可以在运行时覆盖用户,fab infra --user=root但它仍然要求我输入密码。但是,如果我改变env.userenv.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。很明显,可以覆盖设置,但似乎我不能从正常的命令行标志。难道我做错了什么?

4

3 回答 3

1

It's not currently possible to override the default setting from the command line in the way I would want. There's a ticket for it though https://github.com/fabric/fabric/issues/680 and it seem like it will be fixed.

于 2012-08-03T03:49:18.443 回答
0

你有一张为此打开的票,我也展示了那里的例子,更像你在这里展示的。我的猜测是你不能事先在文件中设置 env.user ,因为这是一个明确的硬编码。

于 2012-07-13T14:03:20.300 回答
0

我想你正在寻找:

fab infra:hosts=root@somehost

It's unclear to me whether the same username@... pattern works with roles or roledefs.

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

于 2012-08-02T19:51:03.050 回答