[英]django fabric set hosts for deployment
我想在本地主機中部署我的代碼,並在我使用結構的自動化版本中部署我的實時版本。 我的基本結構文件如下所示:
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 provided_by=([localhost])
在這里做什么。 我猜應該提供本地主機和用戶之類的信息。
為什么我收到此錯誤? 需要幫忙
我不確定為什么除了在文檔中沒有提到主機列表的構建方式之外,它為什么不起作用。 設置主機值的選項有:
env.hosts = ['127.0.0.1']
fab -H 127.0.0.1 setup
fab localhost setup
參見http://docs.fabfile.org/en/1.10/usage/execution.html#how-host-lists-are-constructed
fabric.operations.require(* keys,** kwargs):
檢查共享環境字典中的給定鍵,如果找不到則中止...可選關鍵字參數provider_by可以是函數或函數名稱的列表,或者用戶應能夠執行以設置的單個函數或函數名稱一個或多個鍵; 如果不滿足要求,它將包含在錯誤輸出中。
http://docs.fabfile.org/en/1.10/api/core/operations.html?highlight=require#fabric.operations.require
這就是為什么您收到錯誤消息,要求先運行localhost
,然后setup
:
fab localhost setup
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.