@@ -0,0 +1,955 @@
+from chef import Search%0Afrom chef.api import ChefAPI, autoconfigure%0Afrom chef.exceptions import ChefError%0A%0Aclass Roledef(object):%0A    def __init__(self, name, api):%0A        self.name = name%0A        self.api = api%0A%0A    def __call__(self):%0A        for row in Search('node', 'roles:'+self.name, api=self.api):%0A            yield row.object%5B'fqdn'%5D%0A%0A%0Adef chef_roledefs(api=None):%0A    %22%22%22Build a Fabric roledef dictionary from a Chef server.%0A%0A    Example:%0A%0A        from fabric.api import env, run, roles%0A        from chef.fabric import chef_roledefs%0A%0A        env.roledefs = chef_roledefs()%0A%0A        @roles('web_app')%0A        def mytask():%0A            run('uptime')%0A    %22%22%22%0A    api = api or ChefAPI.get_global() or autoconfigure()%0A    if not api:%0A        raise ChefError('Unable to load Chef API configuration')%0A    roledefs = %7B%7D%0A    for row in Search('role', api=api):%0A        name = row%5B'name'%5D%0A        roledefs%5Bname%5D =  Roledef(name, api)%0A    return roledefs%0A

Add chef.fabric to use Chef roles in Fabric.