python - Call /etc/sudoers commands from fabric -


in /etc/sudoers have:

# allow picky user restart own gunicorn process picky all=(all) nopasswd: /usr/bin/supervisorctl restart picky 

i can indeed run command picky user:

$ su picky $ sudo supervisorctl restart picky 

in fabfile.py have following:

from fabric.api import sudo  def restart():     sudo("supervisorctl restart picky") 

however, when run fabric file, still prompts password:

[picky@myhost] sudo: supervisorctl restart picky [picky@myhost] out: sudo password:  

how can run sudo commands inside fabric such don't need provide password?

edit:

i've noticed works:

from fabric.api import run  def restart():     run("sudo supervisorctl restart picky") 

as noted in https://stackoverflow.com/questions/3737003/can-i-prevent-fabric-from-prompting-me-for-a-sudo-password, when use fabric sudo command command sent shell. real command executed contains call /bin/bash in it, why doesn't match sudoer entry.

to around that, add shell=false call:

from fabric.api import sudo  def restart():     sudo("supervisorctl restart picky", shell=false) 

you might have add full path supervisorctl.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -