fab-user
[Top][All Lists]
Advanced

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

Re: [Fab-user] setting hosts


From: Jeff Forcier
Subject: Re: [Fab-user] setting hosts
Date: Mon, 11 May 2009 21:56:26 -0400

Hi all,

Just basically redid the roles to be exactly equivalent with hosts, so
they're hopefully quite un-broken now.

The deal is that you may set the hosts and/or roles to execute on, in
a number of ways:

* Globally on the command line (new --hosts, --roles options)
* Per-command on the command line (as before, but now you can do this
with roles too, not just hosts)
* Via the decorators (same as before)
* By tweaking env.hosts or env.roles in your fabfile somewhere (though
the --hosts/--roles options actually "preset" the env vars, so you may
want to append to env.hosts/roles in order to "play nice" with the CLI
args)

And, to SET the roles, you need to define or update another env var,
env.roledefs (a dict). I went this route for now, instead of using
fabric.state.roles, because I felt it was a bit simpler. We could just
as easily have that dict be a top-level item in fabric.state as it
used to be (though it still needs to be named 'roledefs' or something
other than 'roles' in order to not be confused with the decorator or
the env var).

If anyone has strong feelings about how to set roles, please speak up.
For example, Capistrano (IIRC) has top level functions for defining
roles, something like "role('foo', ['a', 'b', 'c'])". I felt that
allowing direct access to the role dictionary was more Pythonic, but
that's just my take.

I have also updated the documentation for all of this role/host
related stuff and pushed those to the site; it's still in the usage
section.

Best,
Jeff

On Mon, May 11, 2009 at 5:31 PM, Jeff Forcier <address@hidden> wrote:
> Right, the point is that it's not env.roles, but actually
> fabric.state.roles (which is not exported in the API, and is not part
> of the 'env' dictionary). As I mentioned, this is why roles are
> basically broken right now.
>
> You can, however, directly access fabric.state.roles, and it should
> work, though I haven't tested this myself:
>
> from fabric.api import *
> import fabric.state.roles  # make sure you don't do "from f.s import roles"!
>
> fabric.state.roles.home = ['mydomain']
>
> ...and so forth...
>
>
> If I have the time I'll try and fix this tonight (and if not tonight,
> soon). Just realized, also, that there would be a name conflict
> between state.roles and decorators.roles (if both were to be imported
> via fabric.api), so I'll have to figure out the best way to address
> that.
>
> -Jeff
>
> On Mon, May 11, 2009 at 5:21 PM, Jeremy M. Jones <address@hidden> wrote:
>> I'm still getting an attribute error when I have this:
>>
>>  1 from fabric.api import run, put, roles, env
>>  2
>>  3 env.user = 'jmjones'
>>  4 env.roles.home = ['mydomain']
>>  5 env.roles.ezr = ['192.168.1.20']
>>  6 #env.hosts = []
>>  7
>>  8 @roles('home', 'ezr')
>>  9 def all():
>>  10     pass
>>  11
>>  12 @roles('ezr')
>>  13 def ezr():
>>  14     pass
>>  15
>>  16 @roles('home')
>>  17 def home():
>>  18     pass
>>  19
>>  20 def ls():
>>  21     run('ls')
>>
>> Here's the command I used:
>>
>> (fab_git)address@hidden:~/fab/home$ fab ezr ls
>> /home/jmjones/python/fab_git/lib/python2.6/site-packages/pycrypto-2.0.1-py2.6-linux-x86_64.egg/Crypto/Hash/SHA.py:6:
>> DeprecationWarning: the sha module is deprecated; use the hashlib module
>> instead
>> /home/jmjones/python/fab_git/lib/python2.6/site-packages/pycrypto-2.0.1-py2.6-linux-x86_64.egg/Crypto/Hash/MD5.py:6:
>> DeprecationWarning: the md5 module is deprecated; use hashlib instead
>> Traceback (most recent call last):
>>  File "build/bdist.linux-x86_64/egg/fabric/main.py", line 339, in main
>>  File "build/bdist.linux-x86_64/egg/fabric/main.py", line 116, in
>> load_fabfile
>>  File "/home/jmjones/fab/home/fabfile.py", line 4, in <module>
>>    env.roles.home = ['mydomain']
>>  File "build/bdist.linux-x86_64/egg/fabric/state.py", line 64, in
>> __getattr__
>> AttributeError
>>
>> - jmj
>>
>> On May 11, 2009, at 1:28 PM, Patrick J McNerthney wrote:
>>
>>> Try:
>>>
>>> env.roles.webserver = ['www1', 'www2']
>>> env.roles.dbserver = ['db1']
>>> @roles('webserver', 'dbserver')
>>> def my_func():
>>>      pass
>>>
>>> Pat McNerthney
>>> ClearPoint Metrics, Inc.
>>>
>>>
>>> Jeremy M. Jones wrote:
>>>>
>>>> What's the canonical way of creating groups of hosts and then selecting
>>>> that group (or sets of groups) to execute for a particular function at
>>>> runtime?  I initially thought that it included using the roles, but I can't
>>>> get that working right.  According the the docstrings in the decorators.py
>>>> module, using roles should look like this:
>>>>
>>>> 41         env.webserver = ['www1', 'www2']
>>>> 42         env.dbserver = ['db1']
>>>> 43
>>>> 44         @roles('webserver', 'dbserver')
>>>> 45         def my_func():
>>>> 46             pass
>>>>
>>>> But when I run something like this:
>>>>
>>>>  1 from fabric.api import run, put, roles
>>>>  2 from fabric.state import env
>>>>  3
>>>>  4 env.user = 'myuser'
>>>>  5 env.home = ['my.host.com']
>>>>  6 env.ezr = ['192.168.1.20']
>>>>  7 env.hosts = []
>>>>  8
>>>>  9 @roles('home', 'ezr')
>>>> 10 def all():
>>>> 11     pass
>>>> 12
>>>> 13 @roles('ezr')
>>>> 14 def ezr():
>>>> 15     pass
>>>> 16
>>>> 17 @roles('home')
>>>> 18 def home():
>>>> 19     pass
>>>> 20
>>>> 21 def ls():
>>>> 22     run('ls')
>>>>
>>>> With a command line looking like this::
>>>>
>>>>   fab ezr ls
>>>>
>>>> I get an error like this::
>>>>
>>>> Traceback (most recent call last):
>>>>  File "build/bdist.linux-x86_64/egg/fabric/main.py", line 391, in main
>>>>  File "build/bdist.linux-x86_64/egg/fabric/main.py", line 305, in
>>>> get_hosts
>>>> KeyError: 'ezr'
>>>>
>>>> I figured that attributes on the "env" object would be interpreted as
>>>> roles, but that doesn't appear to be the case.  And even if this worked
>>>> properly, I'm not sure that this would do what I wanted it to do.  It seems
>>>> that it would set the .roles attribute on the decorated functions with the
>>>> specified roles rather than adding the hosts for those roles to some global
>>>> run registry or something like that.
>>>>
>>>> Anyway, are there working examples for the current 0.9 release that will
>>>> allow me to sort of do what I want to do?  I can monkey around with sets 
>>>> and
>>>> the hosts list with various functions, but it seems like there should be a
>>>> cleaner to do this.
>>>>
>>>> - jmj
>>>>
>>>>
>>>> _______________________________________________
>>>> Fab-user mailing list
>>>> address@hidden
>>>> http://lists.nongnu.org/mailman/listinfo/fab-user
>>>
>>
>>
>>
>> _______________________________________________
>> Fab-user mailing list
>> address@hidden
>> http://lists.nongnu.org/mailman/listinfo/fab-user
>>
>




reply via email to

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