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 13:30:42 -0400

Yea, the roles are actually out of sync with their documentation: the
docstring for @roles claims they're normal env keys, but the
implementation is actually using a separate fabric.state module-level
dict, fabric.state.roles.

This is totally my fault and I expect to fix it in the next day or
two. Not entirely sure in which *direction* -- I think probably
keeping the separate roles namespace is cleaner, so I would then
update the @roles docstring -- but it will get fixed.

Apologies for the confusion!

Best,
Jeff

On Mon, May 11, 2009 at 1:28 PM, Patrick J McNerthney
<address@hidden> 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]