Fabric: Local command usage
I want execute a command which needs sudo in local machine. So as the documen开发者_如何学Pythontation suggests, I used the local command, but its asking me to enter the password. How can I avoid this? Is there some place where I can save my local machine password?
local('sudo /etc/init.d/tomcat6 start',capture=True)
If you do not plan to share the fabfile you can use:
echo "password\n" | sudo -S /etc/init.d/tomcat6 start
according to the sudo man page:
The -S (stdin) option causes sudo to read the password from the standard input instead of the terminal device. The password must be followed by a newline character.
Check the visudo
command, which will allow you to edit the /etc/sudoers
file, in which you can define users, commands and password-requirements on a machine (e.g. user mlzboy does not need to enter password in order to execute /etc/init.d/tomcat6
). Don't forget this can create a security problem.
Sudoers manual
If you want to use sudo but on the loopback ip:
from fabric.api import sudo,env
env.hosts =['127.0.0.1']
sudo('aptitude search fabric')
No need to edit sudoers, given you have an ssh server running locally.
精彩评论