fab-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Fab-user] execute command depending on role


From: Stroehmann, James
Subject: Re: [Fab-user] execute command depending on role
Date: Wed, 23 Jan 2013 16:42:06 -0500

That was exactly it, thanks!

 

 

 

From: Todd DeLuca [mailto:address@hidden
Sent: Wednesday, January 23, 2013 4:41 PM
To: Stroehmann, James
Cc: address@hidden
Subject: Re: [Fab-user] execute command depending on role

 

This should work for you.  I think the main problem is how you check the that the host_string is in the roledefs dict.

 

from fabric.api import env, run, task

 

env.roledefs = {

    'prodmail': ['address@hidden', 'address@hidden'],

    'prodweb': ['address@hidden', 'address@hidden']

}

 

@task

def OOpsBroke():

    if env.host_string in env.roledefs['prodmail']:

        print 'uname -n', env.host_string

    elif env.host_string in env.roledefs['prodweb']:

        print 'uname -a', env.host_string

    else:

        print 'uname -v', env.host_string

 

 

On Wed, Jan 23, 2013 at 12:18 PM, Stroehmann, James <address@hidden> wrote:

[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



 

--
Todd DeLuca
http://todddeluca.com

 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]