fab-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Fab-user] constructing host lists from a file


From: Martin-Louis Bright
Subject: Re: [Fab-user] constructing host lists from a file
Date: Tue, 10 Aug 2010 23:54:02 -0400

Awesome. Thank you, this is precisely what I was hoping for.

However I think there's a bug in the documentation. On this page, it says

"Since the env vars are checked for each host, this means that if you have the need, you can actually modify env in one task and it will affect all following tasks"

What it should say is:

"Since the env vars are checked for each task, this means that if you have the need, you can actually modify env in one task and it will affect all following tasks"

Right?

Martin



On Tue, Aug 10, 2010 at 4:52 PM, Jeff Forcier <address@hidden> wrote:
> Hi Martin,
>
> On Tue, Aug 10, 2010 at 4:27 PM, Martin-Louis Bright <address@hidden> 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
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]