I want to deploy my code in localhost and my live version for this automation i used fabric. My basic fabric file look like:
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')
For now i only want to deploy to my local machine. When I do this it gives me erro saying
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
What does provided_by=([localhost])
do in here. I guess it should provide the information like hosts and user in localhost.
Why I am getting this error ?? Need help
I'm not sure why that doesn't work other than it's not mentioned in the docs as how host lists get constructed. Your options for setting the host value are:
env.hosts = ['127.0.0.1']
globally in your fabfile fab -H 127.0.0.1 setup
fab localhost setup
See http://docs.fabfile.org/en/1.10/usage/execution.html#how-host-lists-are-constructed
fabric.operations.require(*keys, **kwargs):
Check for given keys in the shared environment dict and abort if not found... The optional keyword argument provided_by may be a list of functions or function names or a single function or function name which the user should be able to execute in order to set the key or keys; it will be included in the error output if requirements are not met.
http://docs.fabfile.org/en/1.10/api/core/operations.html?highlight=require#fabric.operations.require
That why you get the error message saying to run localhost
first, then setup
:
fab localhost setup
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.