Hi Jeff, A text file with host strings delimited by newlines could be simply loaded like so:
with open('/path/to/file') as fd: env.hosts = [x.strip() for x in fd] # To clear out the trailing newlines Or you could load from a Web service spitting out the same sort of format: env.roledefs = {'web': urllib.urlopen('http://my/webservice/').read().split()} Finally, roles are lazily evaluated, so you can store callable objects as their values and they'll get evaluated only if that role is referenced in the tasks you're running (as opposed to any time the fabfile is loaded, which means that even eg "fab --list" has a bit of a lag to it). To do this, you could just use a lambda to wrap the above, like so: env.roledefs = {'web': lambda: urllib.urlopen('url').read().split()} Now that urlopen() call is only executed if you mark a task as @roles('web') and call that task on the command line. HTH, Jeff On Wed, Nov 3, 2010 at 11:21 AM, Jeff Honey <je...@pona.net> wrote: > Can anyone share some experience or practical examples of loading hosts > (and/or roles) either from text file input or loaded dynamically into/out of > arrays? Actually, I seem to remember that arrays are "lists" with > Python...right? > > I'm looking to branch out a bit and stop hard-coding roles in my fabfile and > load them on-the-fly. > > > -- > ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ > ¤ kyoboku kazeoshi ¤ > ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ > _______________________________________________ > Fab-user mailing list > Fab-user@nongnu.org > http://lists.nongnu.org/mailman/listinfo/fab-user > -- Jeff Forcier Unix sysadmin; Python/Ruby developer http://bitprophet.org _______________________________________________ Fab-user mailing list Fab-user@nongnu.org http://lists.nongnu.org/mailman/listinfo/fab-user