Calum
Calum

Reputation: 2130

how to do sudo -E ..... in fabric?

I have a fabric script that currently uses commands such as:

sudo('pip install virtualenv --upgrade --use-mirrors')

what i want to know is how do i pass sudo the -E option, to run this?

sudo -E pip install virtualenv --upgrade --use-mirrors

EDIT:

tried this:

sudo('pip install virtualenv --upgrade --use-mirrors, -E')

but that seems to pass the option to pip install instead of sudo

EDIT 2:

env.sudo_prefix = "sudo -E -S -p '%(sudo_prompt)s'"

is giving me a TypreError: format requires a mapping

EDIT 3:

env.sudo_prefix = "sudo -E -S -p '%(sudo_prompt)s'" % env

is giving me a TypreError: not all arguments converted during string formating

Upvotes: 1

Views: 892

Answers (2)

LtWorf
LtWorf

Reputation: 7608

That's a pretty bad idea, it would force you to store passwords clear text and so on. The right™ way of doing it is running

$ sudo visudo

and configuring sudo to allow your user to run pip without prompting for a password.

Otherwise you're creating a number of security problems.

Upvotes: 0

Redian
Redian

Reputation: 334

From the fabric source file . the sudo method signature is as follows :

def sudo(command, shell=True, pty=True, combine_stderr=None, user=None,
    quiet=False, warn_only=False, stdout=None, stderr=None, group=None,
    timeout=None):

the examples provided do not show any such scenario (amazingly) i would have bet otherwise.

sudo("~/install_script.py")
        sudo("mkdir /var/www/new_docroot", user="www-data")
        sudo("ls /home/jdoe", user=1001)
        result = sudo("ls /tmp/")
        with settings(sudo_user='mysql'):
            sudo("whoami") # prints 'mysql'

I would suggest you supply the user key.

Have a look at this open ticket :

https://github.com/fabric/fabric/issues/503

Have your tried running ur command with run()

run('sudo -E pip install virtualenv --upgrade --use-mirrors')

Upvotes: 1

Related Questions