下面是一个小代码,我一直在努力在远程服务器上安装软件包。代码运行良好,软件包正在安装中,但一旦安装完成,系统会提示我输入密码。知道是什么引起的吗?在import re
import os
import sys
from datetime import datetime
import git
from fabric.api import run, local, cd, env
from fabric.contrib.files import exists, append
from fabric.operations import put, sudo
class WebAppConf():
APPLICATION_DIR = '/home/xxx/webapps'
APPLICATION_USER = '' # mazban
APPLICATION_ROOT = ''
APPLICATION_TEMPLATE_SETTINGS = 'com_work' # see config/settings/templates
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
###########################################################################
# CONFIGURATION FOR DEVELOPMENT, STAGING, TESTING AND PRODUCTION SETTINGS - START #
###########################################################################
def test():
env.hosts = env.hosts or ['192.168.3.139', ]
env.user = 'xxx'
env.password = "xxx"
env.warn_only = True
env.no_keys = True
# App variables
WebAppConf.APPLICATION_DIR = '/home/xxx/webapps' # application physical location
WebAppConf.APPLICATION_USER = env.user
WebAppConf.APPLICATION_ROOT = env.user
WebAppConf.APPLICATION_TEMPLATE_SETTINGS = 'testing'
def staging():
env.hosts = env.hosts or ['xxx-staging.com', ]
env.user = 'xxx'
env.password = "xx"
env.warn_only = True
env.no_keys = True
def production():
"""
Production will deploay on one or many frontend's
for peroduction deployment no password will be used and only ssh keys
"""
env.hosts = env.hosts or ['xxx.com', ]
env.user = APPLICATION_USER
env.password = "xx"
env.warn_only = True
env.no_keys = True
##########################################################################
# CONFIGURATION FOR DEVELOPMENT, STAGING, TESTING AND PRODUCTION SETTINGS - END #
##########################################################################
def firstrun():
## if no env is selected it will fail
if not env.hosts:
print 'Error: must use environment (e.g fab prod %s)' % 'firstrun'
exit()
# validate the OS distribution and version
LINUX_DISTRIBUTION = ''
if run('cat /etc/*-release|grep DISTRIB_ID').upper().__contains__('UBUNTU'):
LINUX_DISTRIBUTION = 'UBUNTU'
print 'Ubuntu Linux'
elif run('cat /etc/*-release|grep DISTRIB_ID').upper().__contains__('DEBIAN'):
LINUX_DISTRIBUTION = 'DEBIAN'
print 'Debian Linux'
else:
print 'Exiting (Cannot recognize linux distribution).'
exit()
# Linux version
LINUX_VERSION = run('cat /etc/*-release|grep DISTRIB_RELEASE')
print 'Linux version %s' % LINUX_VERSION.replace('DISTRIB_RELEASE=', '')
# GET PYTHON VERSIONS
version = run("python2.6 -V").split()[1]
if version[0]=='2' and version[2]=='6' and version[4]=='6':
# version installed matches the requirements
print 'Python version is compatible with this application (2.6.6).'
else:
print 'Python version is not compatible with this application %s' % version[0]+'.'+version[2]+'.'+version[4]
_sudo('apt-get install python2.6')
version = run("python2.6 -V").split()[1]
if version[0]=='2' and version[2]=='6' and version[4]=='6':
print 'python 2.6.6 installed successfully.'
else:
print 'cannot install python 2.6.6'
exit()
if not exists('/usr/bin/pip'):
print "installing python-pip package"
_sudo('apt-get install python-pip')
if not exists('/usr/local/bin/virtualenv'):
print 'installing virtualenv'
_sudo('pip install -E /usr/bin/python2.6 virtualenv')
# application directory check
MAKE_APPLICATION_DIR = False
if not exists(WebAppConf.APPLICATION_DIR):
MAKE_APPLICATION_DIR = True
print '%s does not exist.' % WebAppConf.APPLICATION_DIR
run('mkdir -p %s' % WebAppConf.APPLICATION_DIR)
print '%s application directory is created successfully.' % WebAppConf.APPLICATION_DIR
# change to application root directory and start preparing for applications
#with cd(WebAppConf.APPLICATION_DIR):
return
执行函数时输出
^{pr2}$