关于python:如何强制fabric使用env.password设置

how to force fabric to use env.password setting

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

1
2
3
4
5
6
7
8
9
from fabric.api import *


env.password ="mypassword"

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

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

1
2
3
4
5
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或run时,它会说:

"找不到主机。请为连接指定(单个)主机字符串:"

如何使用我设置的密码使其运行?谢谢你


我已经开始工作了。它不漂亮。

1
2
3
4
5
6
7
8
9
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上创建了您的用户)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$ 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]
...