Skip to content

Instantly share code, notes, and snippets.

@harobed
Created February 1, 2014 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harobed/8750386 to your computer and use it in GitHub Desktop.
Save harobed/8750386 to your computer and use it in GitHub Desktop.
from contextlib import nested
from fabric.api import task, run, settings, env
def switch_user(user):
return nested(settings(
user=user,
host_string="%s@%s:%s" % (user, env['host'], env['port'])
))
@task
def install():
with switch_user('foobar'):
run('whoami') # => foobar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment