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

2010-08-11 Thread Jeff Forcier
On Tue, Aug 10, 2010 at 11:54 PM, Martin-Louis Bright
mlbri...@gmail.com wrote:

 However I think there's a bug in the documentation. snip Right?

Yup, that's a typo -- thanks for catching it :) Just fixed, so 0.9.2's
docs will include that change.

Best,
Jeff

-- 
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


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

2010-08-10 Thread Jeff Forcier
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


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

2010-08-10 Thread Martin-Louis Bright
Awesome. Thank you, this is precisely what I was hoping for.

However I think there's a bug in the documentation. On
thishttp://docs.fabfile.org/0.9.1/usage/execution.htmlpage, 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 j...@bitprophet.org wrote:
 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