On the fabric website, this example is given:
from fabric.api import env
env.roledefs = {
'web': {
'hosts': ['www1', 'www2', 'www3'],
'foo': 'bar'
},
'dns': {
'hosts': ['ns1', 'ns2'],
'foo': 'baz'
}
}
As far as I can tell from the documentation, this setup should give the env dict key 'foo' the value 'bar' when executing on hosts 'www1', 'www2', 'www3'. I cannot get this behavior, though fabric does correctly determine hosts. An example fabfile:
env.foo = 'WRONG'
@task()
def set_role():
env.roles.append('web')
@task()
def print_foo():
print env.foo
The example command:
fab set_role print_foo
Unexpected output:
[www1] Executing task 'print_foo'
WRONG
[www2] Executing task 'print_foo'
WRONG
[www3] Executing task 'print_foo'
WRONG
Done.
Am I misunderstanding the purpose of this? How can I make it so that one server sees a different value for a key then another without too much trouble?
I am using fabric 1.10.0
Just an answer to this:
env.roledefs = {
'prod': {
'hosts':['server1','server2'],
'path':'/opt/prod'
},
'stag': {
'hosts':['server3','server4'],
'path':'/opt/stag'
}
}
@roles('prod')
def runa():
role = env.effective_roles[0]
print env.roledefs[role]['path']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With