在服务器上架设了jenkins之后,使用jenkins进行部署,但一直碰到报错。找不到原因,在百度、GOOGLE上也找了好多文章,多没有给出答案。报错的内容如下:
+ fab -f deploy/fabfile.py production deploy
/usr/local/python27/lib/python2.7/getpass.py:83: GetPassWarning: Can not control echo on the terminal.
passwd = fallback_getpass(prompt, stream)
Warning: Password input may be echoed.
根据经验这上面的提示的意思就是登录的时候被提示输入密码,但fabric不能捕获到控制台输出和输入,就出错了。但我明明在我的fabfile.py里写了密码,而fabric在执行的时候却不能提取密码。内容如下:
@task
def production():
env.user = "root"
env.hosts = ['123.1.101.23']
env.passwords = {'123.1.101.23':'123456'}
env.base_dir = "/home/testjenkins"
推断应该是jenkins里有相关的设置导致,因为我同样的fabfile.py程序在其它的服务器上是可以运行的,在Google了一遍之后未找到答案,找到了一点东西(在fabric的文档里:http://docs.fabfile.org/en/1.12/usage/env.html),就是env里确实是有配置可以对此进行处理:
abort_on_prompts
Default: False
When True, Fabric will run in a non-interactive mode, calling abort anytime it would normally prompt the user for input (such as password prompts, “What host to connect to?” prompts, fabfile invocation of prompt, and so forth.) This allows users to ensure a Fabric session will always terminate cleanly instead of blocking on user input forever when unforeseen circumstances arise.
但此值默认已经是false,而在另一篇文章中更是提到这是一个BUG,且在新的版本中已经修复:https://bugs.launchpad.net/pantheon/+bug/618795 截图如下:
这个问题困扰了好多天了,上次碰到之后尝试找了很多文章,但未找到解决的办法,今天再好好地查找了一翻,依然没有答案。今天我在命令行下尝试运行fabric,
执行命令:fab production deploy 执行时确实看到它的提示密码输入:
最终依然在网上没有找到解决办法,都快准备重装python和jenkins了。但就在最后关头看到了网上一个不经意的地方用这种方式写了几惑密码:env.passwords = {'name@address': 'password'}。而我根据这种格式修改了fabfile.py中的passwords后OK了。经过多次测试,使用这种格式:env.passwords = {'root@123.1.101.23':'123456'}在命令行下和在jenkins的操作平台下都能成功,但目前尚不知道{'123.1.101.23':'123456'}这种格式为什么不行,因为我在其它的服务器上都是这样的写法。也许是fabric的配置的原因,或者是版本的原因。