--user=root不';似乎没有覆盖fabric env.user,为什么?
我有一个文件,其中包含:--user=root不';似乎没有覆盖fabric env.user,为什么?,fabric,Fabric,我有一个文件,其中包含: 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_s
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-rserver
所以我想当我运行fab infra--user=root
时,我可以用--user=root或-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-rserver
时,它就可以工作了。很明显,可以覆盖该设置,但似乎无法从正常的命令行标志进行覆盖。我做错什么了吗?你有一个问题,我在那里也展示了一个例子,更像你在这里展示的那样。我猜您不能事先在文件中设置env.user,因为这是一个明确的硬编码。我想您正在寻找:
fab infra:hosts=root@somehost
我不清楚相同的username@...
模式适用于角色或角色定义
目前无法按我所希望的方式从命令行覆盖默认设置。不过有一张罚单,看起来它会被修复。您正在运行哪个版本的fabric?我无法在命令行上指定主机,因为它们一直在变化。看来你不能这么做: