|
From: | Stroehmann, James |
Subject: | Re: [Fab-user] execute command depending on role |
Date: | Wed, 23 Jan 2013 16:30:36 -0500 |
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: address@hidden [mailto:address@hidden On Behalf Of Stroehmann, James [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. --- |
[Prev in Thread] | Current Thread | [Next in Thread] |