Python – Fabric – sudo -u

djangofabricpythonsudo

I'm using fabric to launch a command on a remote server.
I'd like to launch this command as a different user (neither the one connected nor root).

def colstat():
  run('python manage.py collectstatic --noinput')

Trying

def colstat():
  sudo('-u www-data python manage.py collectstatic --noinput')

Oviously this won't work because -u will be considered as a command and not an option of sudo

out: /bin/bash: -u : command not found

(www-data is the user which should run the command)
How can I use www-data to run my command from Fabric ?

Best Answer

Judging from the documentation:

sudo('python manage.py collectstatic --noinput', user='www-data')
Related Topic