Fabric Integration¶
-
chef.fabric.chef_roledefs(api=None, hostname_attr=['cloud.public_hostname', 'fqdn'], environment=<object object>)¶ Build a Fabric roledef dictionary from a Chef server.
Example:
from fabric.api import env, run, roles from chef.fabric import chef_roledefs env.roledefs = chef_roledefs() @roles('web_app') def mytask(): run('uptime')
hostname_attrcan either be a string that is the attribute in the chef node that holds the hostname or IP to connect to, an array of such keys to check in order (the first which exists will be used), or a callable which takes aNodeand returns the hostname or IP to connect to.To refer to a nested attribute, separate the levels with
'.'e.g.'ec2.public_hostname'environmentis the ChefEnvironmentname in which to search for nodes. If set toNone, no environment filter is added. If set to a string, it is used verbatim as a filter string. If not passed as an argument at all, the value in the Fabric environment dict is used, defaulting to'_default'.Note
environmentmust be set toNoneif you are emulating Chef API version 0.9 or lower.New in version 0.1.
New in version 0.2: Support for iterable and callable values for the``hostname_attr`` argument, and the
environmentargument.
-
chef.fabric.chef_environment(name, api=None)¶ A Fabric task to set the current Chef environment context.
This task works alongside
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()
$ fab env:production deploy
The task can be configured slightly via Fabric
envvalues.env.chef_environment_task_aliassets the task alias, defaulting to “env”. This value must be set beforechef.fabricis imported.env.chef_environment_validatesets ifEnvironmentnames should be validated before use. Defaults to True.New in version 0.2.