|
From: | Stroehmann, James |
Subject: | [Fab-user] execute command depending on role |
Date: | Wed, 23 Jan 2013 12:06:59 -0500 |
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 -v') @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 'OOpsWorks' address@hidden run: uname -v address@hidden out: #1 SMP Sun Jul 31 16:44:56 EDT 2011 address@hidden Executing task 'OOpsWorks' 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] |