2015-10-07 88 views
1

我想部署我的代碼在本地主機和我的活動版本爲此自動化我使用結構。我的基本結構文件如下所示:django fabric設置部署主機

def localhost(): 
    "Use the local virtual server" 
    env.hosts = ['127.0.0.1'] 
    env.user = 'user' 
    env.path = '/var/www/html/{}'.format(env['project_name']) 
    env.virtualhost_path = env.path 

def webserver(): 
    "Use the actual webserver" 
    env.hosts = ['www.example.com'] 
    env.user = 'username' 
    env.path = '/var/www/html/{}'.format(env['project_name']) 
    env.virtualhost_path = env.path 

def setup(): 
require('hosts', provided_by=[localhost]) 
require('path') 

sudo("apt-get update -y") 
sudo("apt-get install git -y") 
sudo("apt-get install postgresql libpq-dev python-dev python-pip -y") 
sudo("apt-get install redis-server -y") 
sudo("apt-get install nginx -y") 

sudo('aptitude install -y python-setuptools') 
sudo('apt-get install python-pip') 
sudo('pip install virtualenv virtualenvwrapper') 

現在我只想部署到本地計算機。當我這樣做,它給了我錯誤的說

The command 'setup' failed because the following required environment variable was not defined: 
hosts 

Try running the following command prior to this one, to fix the problem: 
localhost 

什麼provided_by=([localhost])在這裏做。我想它應該提供像本地主機和用戶一樣的信息。

爲什麼我得到這個錯誤? 需要幫助

回答

0

fabric.operations.require(*鍵,** kwargs):

檢查在共享環境字典給出的按鍵和中止如果沒有 發現...可選關鍵字參數provided_by可能是一個列表功能或功能名稱或用戶應該能夠執行的單個功能或功能名稱,以便設置一個或多個鍵;如果不符合要求,它將包含在錯誤輸出中。

http://docs.fabfile.org/en/1.10/api/core/operations.html?highlight=require#fabric.operations.require

這就是爲什麼你會得到錯誤信息,說跑localhost,再setup

fab localhost setup