|
From: | Todd DeLuca |
Subject: | Re: [Fab-user] execute command depending on role |
Date: | Wed, 23 Jan 2013 16:41:00 -0500 |
[Cut and paste error corrected]
I am trying to get fabric to execute different commands based on which role they are placed in, but my if statement is not working as expected. In the fabfile below, the first task works (OOpsWorks) but the second only executes the “else”:
---
from fabric.api import *
env.roledefs = {
'prodmail': ['address@hidden, 'address@hidden,
'prodweb': ['address@hidden', 'address@hidden']
}
@task
def OOpsWorks():
run('uname -n')
@task
def OOpsBroke():
if env.host_string in env.roledefs == 'prodmail':
run('uname -n')
elif env.host_string in env.roledefs == 'prodweb':
run('uname -a')
else:
run('uname -v')
----
# fab –R prodmail OOpsWorks
address@hidden Executing task 'OOpsWorks'
address@hidden run: uname -n
address@hidden out: mail1.tld
address@hidden Executing task 'OOpsWorks'
address@hidden run: uname -n
address@hidden out: mail2.tld
Done.
Disconnecting from address@hidden... done.
Disconnecting from address@hidden... done.
---
# fab –R prodmail OOpsBroke
address@hidden Executing task 'OOpsBroke'
address@hidden run: uname -v
address@hidden out: #1 SMP Sun Jul 31 16:44:56 EDT 2011
address@hidden Executing task 'OOpsBroke'
address@hidden run: uname -v
address@hidden out: #1 SMP Sun Jul 31 16:44:56 EDT 2011
Done.
Disconnecting from address@hidden... done.
Disconnecting from address@hidden... done.
---
_______________________________________________
Fab-user mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/fab-user
[Prev in Thread] | Current Thread | [Next in Thread] |