3

以下结构脚本是我需要使用的开源代码,不幸的是我不熟悉这些东西。结构文件以:

from fabric.api import *
import time

env.user = 'aegir'
env.shell = '/bin/bash -c'

# Download and import a platform using Drush Make
def build_platform(site, profile, webserver, dbserver, makefile, build):
  print "===> Building the platform..."
  run("drush make %s /var/aegir/platforms/%s" % (makefile, build))

当 Git 推送触发新构建时,结构文件由 Jenkins 服务器运行。执行此文件时,第一个远程操作(最后一行)会导致以下错误。

/usr/lib/python2.6/getpass.py:83: GetPassWarning: Can not control echo on the terminal.
  passwd = fallback_getpass(prompt, stream)
Warning: Password input may be echoed.
Password for aegir@o1.sub.aegir.local: ===> Building the platform...
[o1.sub.aegir.local] run: drush make https://raw.github.com/mig5/builds/master/mig5_platform.build /var/aegir/platforms/20121011010955
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.6/fabric/main.py", line 435, in main
    commands[name](*args, **kwargs)
  File "/usr/local/bin/fabfile.py", line 11, in build_platform
    run("drush make %s /var/aegir/platforms/%s" % (makefile, build))
  File "/usr/lib/pymodules/python2.6/fabric/network.py", line 390, in host_prompting_wrapper
    return func(*args, **kwargs)
  File "/usr/lib/pymodules/python2.6/fabric/operations.py", line 414, in run
    channel = connections[env.host_string]._transport.open_session()
  File "/usr/lib/pymodules/python2.6/fabric/network.py", line 65, in __getitem__
    self[real_key] = connect(user, host, port)
  File "/usr/lib/pymodules/python2.6/fabric/network.py", line 219, in connect
    password = prompt_for_password(password, text)
  File "/usr/lib/pymodules/python2.6/fabric/network.py", line 279, in prompt_for_password
    new_password = getpass.getpass(password_prompt)
  File "/usr/lib/python2.6/getpass.py", line 83, in unix_getpass
    passwd = fallback_getpass(prompt, stream)
  File "/usr/lib/python2.6/getpass.py", line 118, in fallback_getpass
    return _raw_input(prompt, stream)
  File "/usr/lib/python2.6/getpass.py", line 135, in _raw_input
    raise EOFError
EOFError
Build step 'Execute shell' marked build as failure
Finished: FAILURE

我是否必须为 aegir 用户指定密码?我试图在 下包含(我在远程机器上env.password = ''删除了 Aegir 的用户密码) ,但这并没有解决任何问题。passwd --delete aegirenv.user = 'aegir'

4

3 回答 3

2

SSH 服务禁止没有密码的用户远程访问。您可以aegir在机器上和 fabfile 中为用户设置密码。

于 2012-10-14T10:23:26.643 回答
1

要求登录。为避免交互,您可以从 FABRIC 机器复制公钥并粘贴到 TARGET 机器的 ~/.ssh/authorized_keys

确保: 不包括或排除任何不是密钥的内容(例如引入换行符),密钥必须按原样复制。

并这样做:

chmod 600 ~/.ssh/authorized_keys
chmod 700 ~/.ssh/*
于 2014-08-26T11:00:56.683 回答
0

使用这个功能和炸弹!

output['running']  = False     # Avoid fabric to output what it is doing behind the scenes
output['stdout']   = False     # Do not show stdout
output['stderr']   = False     # Do not show stderr
output['status']   = False     # Prevent fabric from using print in some situations (at least in disconnect_all)
output['warnings'] = False     # Avoid fabric from showing messages about failed commands

def run_it(command, user, host, port, keyfile):
    env.host_string = "%s@%s:%s" % (user, host, port)
    env.key_filename = keyfile
    try:
        res = run(command, pty=False, shell=True)
        print "SUCCESS: return_code=%s" % (return_code)
    except Exception, e:
        print "ERROR  : %s" % (e)
        stdout, return_code =  None, None
    return stdout, return_code

PS 不要将密钥列表传递给 env.key_filename

于 2017-04-09T22:32:39.207 回答