[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Fab-user] firing up Fabric again.
From: |
Jeff Forcier |
Subject: |
Re: [Fab-user] firing up Fabric again. |
Date: |
Mon, 20 Feb 2012 14:49:12 -0800 |
Hi Jeff,
On Mon, Feb 20, 2012 at 12:05 PM, Jeff Honey <address@hidden> wrote:
> ...any more elegant solution for Fab users?
There's three ways of executing a given task/function on a given role.
Let's say we have a "stuff" function/task:
def stuff();
run("command")
and we want to run it on the 'foo' role (whose host list doesn't matter here.)
* Statically select the role name at definition time by slapping @roles on it:
@roles('foo')
def stuff():
...
This is a super old approach, the least flexible, and probably not
what you want.
* Dynamically select the role name at runtime, via the CLI:
$ fab stuff:role=foo
That's per-task, you can also use -R to set the role list globally.
It's unclear if you knew about this, but it works *if* you just want
to select the role when invoking, by hand. This has also been in for
some time :)
* Dynamically select the role at runtime, in-code, with execute():
rolename = 'foo' # Use whatever expression you want here, as long
as it gives you a good role name back :)
execute(stuff, role=rolename)
This feature -- execute() -- was added in Fabric 1.3, and lets you
dynamically pair up a task/function with arbitrary host or role lists.
Read more about it here:
http://docs.fabfile.org/en/1.4.0/api/core/tasks.html#fabric.tasks.execute
Let us know if that doesn't help; from your example code my guess is
you needed either "fab taskname:role=rolename" or execute(). If that's
not right, then please go into a bit more detail about what you
actually need ;)
Best,
Jeff
--
Jeff Forcier
Unix sysadmin; Python/Ruby engineer
http://bitprophet.org