def chef_environment(name, api=None):
"""A Fabric task to set the current Chef environment context.
This task works alongside :func:`~chef.fabric.chef_roledefs` to set the
Chef environment to be used in future role queries.
Example::
from chef.fabric import chef_environment, chef_roledefs
env.roledefs = chef_roledefs()
.. code-block:: bash
$ fab env:production deploy
The task can be configured slightly via Fabric ``env`` values.
``env.chef_environment_task_alias`` sets the task alias, defaulting to "env".
This value must be set **before** :mod:`chef.fabric` is imported.
``env.chef_environment_validate`` sets if :class:`~chef.Environment` names
should be validated before use. Defaults to True.
.. versionadded:: 0.2
"""
if env.get('chef_environment_validate', True):
api = _api(api)
chef_env = Environment(name, api=api)
if not chef_env.exists:
raise ChefError('Unknown Chef environment: %s' % name)
env['chef_environment'] = name
评论列表
文章目录