Got the answer from Bitprophet - the if string needed to be:
"if env.host_string in env.roledefs['prodmail']"
Instead of:
if env.host_string in env.roledefs == 'prodmail':
Thanks!
From: [email protected]
[mailto:[email protected]] On Behalf Of
Stroehmann, James
Sent: Wednesday, January 23, 2013 12:18 PM
To: [email protected]
Subject: Re: [Fab-user] execute command depending on role
[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': ['[email protected], '[email protected]'],
'prodweb': ['[email protected]', '[email protected]']
}
@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
[[email protected]] Executing task 'OOpsWorks'
[[email protected]] run: uname -n
[[email protected]] out: mail1.tld
[[email protected]] Executing task 'OOpsWorks'
[[email protected]] run: uname -n
[[email protected]] out: mail2.tld
Done.
Disconnecting from [email protected]<mailto:[email protected]>... done.
Disconnecting from [email protected]<mailto:[email protected]>... done.
---
# fab -R prodmail OOpsBroke
[[email protected]] Executing task 'OOpsBroke'
[[email protected]] run: uname -v
[[email protected]] out: #1 SMP Sun Jul 31 16:44:56 EDT 2011
[[email protected]] Executing task 'OOpsBroke'
[[email protected]] run: uname -v
[[email protected]] out: #1 SMP Sun Jul 31 16:44:56 EDT 2011
Done.
Disconnecting from [email protected]<mailto:[email protected]>... done.
Disconnecting from [email protected]<mailto:[email protected]>... done.
---
_______________________________________________
Fab-user mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/fab-user