Hi Martin, On Tue, Aug 10, 2010 at 4:27 PM, Martin-Louis Bright <mlbri...@gmail.com> wrote: > it would be nice if I could specify the file > on the command line and be done with it... Is there a disadvantage to > this approach?
Nope, that would work just fine. You could do something like this: def set_hosts(filename): with open(filename) as fd: env.hosts = [x.strip for x in fd.readlines()] def do_stuff(): run("foo") and then execute it like this: $ fab set_hosts:/path/to/hosts_file.txt do_stuff Which would execute "foo" on every host[1] defined in /path/to/hosts_file.txt. That approach works because: * By the time Fabric goes to execute do_stuff(), your set_hosts() has already run, and has thus modified env.hosts. (This is a common idiom.) * Task functions can take arguments on the command line[2] * Fabfiles are Just Python(tm) and so stuff like opening and reading in external files works just fine and is totally encouraged. All of that said -- there've been occasional discussions about various other ways of pre-setting or bootstrapping your execution environment, via config files or importing additional Python files. So this is likely to get even easier in the future. Hope that helps, Jeff [1] http://docs.fabfile.org/0.9.1/usage/execution.html#hosts [2] http://docs.fabfile.org/0.9.1/usage/fab.html#per-task-arguments -- 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