Discussion:
[Fab-user] issue with env.roledefs callable
James Litton
2016-01-05 03:00:54 UTC
Permalink
I’m having an issue with using callables for env.roledefs. The documentation suggests that they will only be called when executing a task that uses the role:
In addition to list/iterable object types, the values in env.roledefs (or value of hosts key in dict style definition) may be callables, and will thus be called when looked up when tasks are run instead of at module load time. (For example, you could connect to remote servers to obtain role definitions, and not worry about causing delays at fabfile load time when calling e.g. fab --list.)

This does not appear to be the case from the following simple example also I could not find a corresponding bug ticket, please let me know if one already exists:
from fabric.api import *

def mycallable():
print "called"
return ["x.example.com"]

env.roledefs = {
"test": mycallable()
}

@task
def mytask():
print "Mytask called on %s" % env.roles


$ fab --list fabfile.py
called
Available commands:

Mytask

$ fab --version
Fabric 1.10.2
Paramiko 1.16.0

Thank you for your help,
James Litton
***@quantcast.com
Brandon Whaley
2016-01-05 07:42:14 UTC
Permalink
You're executing mycallable in your env.roledefs definition. Remove the
"()" from the end and it should work as advertised.
I’m having an issue with using callables for env.roledefs. The
documentation suggests that they will only be called when executing a task
In addition to list/iterable object types, the values in env.roledefs (or
value of hosts key in dict style definition) may be callables, and will
thus be called when looked up when tasks are run instead of at module load
time. (For example, you could connect to remote servers to obtain role
definitions, and not worry about causing delays at fabfile load time when
calling e.g. fab --list.)
This does not appear to be the case from the following simple example also
I could not find a corresponding bug ticket, please let me know if one
from fabric.api import *
print "called"
return ["x.example.com"]
env.roledefs = {
"test": mycallable()
}
@task
print "Mytask called on %s" % env.roles
$ fab --list fabfile.py
called
Mytask
$ fab --version
Fabric 1.10.2
Paramiko 1.16.0
Thank you for your help,
James Litton
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
Loading...