如何强制织物使用 env.password 设置

how to force fabric to use env.password setting

我有一个结构文件,我在其中设置了 env.password,正如我在它的文档中读到的那样:

from fabric.api import *


env.password = "mypassword"

print env.user
print env.password
def update():
    local("sudo apt-get update")

然而当我 运行 文件时,它仍然提示我输入密码:

cchilders@cchilders-Dell-Precision-M3800:~$ fab -f fab_setup_new_linux_box.py update
cchilders
mypassword
[localhost] local: sudo apt-get update
[sudo] password for cchilders: 

我以为这就是设置 env.password 的想法?当我使用 sudo 或 运行 时,它说:

"No hosts found. Please specify (single) host string for connection: "

如何使用我设置的密码制作 运行 东西?谢谢

我让它工作了。不好看

from fabric.api import *


env.password = "mypassword"

print env.user
print env.password
def update():
    local("echo {} | sudo -S apt-get update".format(env.password))

是的,我也不喜欢。这是输出:(是的,我在我的 virtualbox 上创建了你的用户)

$ fab update
cchilders
mypassword
[localhost] local: echo mypassword | sudo -S apt-get update
Hit http://ppa.launchpad.net precise InRelease
Hit http://ppa.launchpad.net precise/main Sources                                                                                   
Hit http://ppa.launchpad.net precise/main amd64 Packages                                                    
Hit http://ppa.launchpad.net precise/main i386 Packages              
Hit http://ppa.launchpad.net precise/main TranslationIndex           
Hit http://security.ubuntu.com precise-security InRelease            
Hit http://ppa.launchpad.net precise/main Translation-en                
Ign http://us.archive.ubuntu.com precise InRelease
Hit http://us.archive.ubuntu.com precise-updates InRelease
Hit http://us.archive.ubuntu.com precise-backports InRelease
Get:1 http://security.ubuntu.com precise-security/main Sources [136 kB] 
Get:2 http://us.archive.ubuntu.com precise Release.gpg [198 B]
Get:3 http://us.archive.ubuntu.com precise-updates/main Sources [494 kB]
Get:4 http://security.ubuntu.com precise-security/restricted Sources [4,476 B]
Get:5 http://security.ubuntu.com precise-security/universe Sources [43.8 kB] 
Get:6 http://security.ubuntu.com precise-security/multiverse Sources [2,198 B]        
Get:7 http://security.ubuntu.com precise-security/main amd64 Packages [563 kB]
...