I have a fabfile with:
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',)
Which I run like fab infra -Rservers.
So I thought I could override the user with --user=root or -u root when I run fab infra --user=root but it’s still asking me for a password. However if I change env.user to env.user = 'root' it doesn’t. I can also use the settings context manager like:
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',)
That works when I do fab infra:root -Rservers. So clearly it’s possible to override the setting, but it seems like I can’t from the normal command line flag. Am I doing something wrong?
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.