Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Fabric 2/Invoke: change directory and use sudo

Tags:

python

fabric

This works just fine

@task
def foo(context):
    with context.cd('/'):
        context.run('pwd')

Output:

/

But this does not:

@task
def bar(context):
    with context.cd('/'):
        context.sudo('pwd', password='mysecretpassword')

Output:

[sudo] password: sudo: cd: Befehl nicht gefunden

How do I get the second example to run?

like image 660
mogoh Avatar asked Jun 13 '18 09:06

mogoh


1 Answers

It turns out, that this is a bug in invoke yet to be fixed.

https://github.com/pyinvoke/invoke/issues/459

Edit:

This is my workaround for now:

context.sudo('bash -c cd "/ && pwd"')

like image 192
mogoh Avatar answered Nov 15 '22 05:11

mogoh