Hi,

I'm trying to run a task on the servers of a role minus some hosts specified on 
the commandline, but I just cannot get it to remember -x...

Here's my code:

------------------------------------------------------------------------------
import os
import paraproxy
from fabric.api import env, run, puts

EXCLUDE_FILE = '~/.hosts_excluded'

env.roledefs = {
    'mailin'    : [ 'host01', 'host02' ],
    'mailout'   : [ 'host03', 'host04' ],
}
env.roledefs['mail'] = env.roledefs['mailin']+env.roledefs['mailout']

def set_excludes(excludes=EXCLUDE_FILE):
    with open(os.path.expanduser(excludes)) as fd:
        env.exclude_hosts.extend([ host.strip() for host in fd.readlines() ])


puts("genrating hostlists...")
puts("Excludes from cli: %s" % ', '.join(env.exclude_hosts))
set_excludes()
puts("Excludes cli/file: %s" % ', '.join(env.exclude_hosts))
puts("... done")

def do_date():
    run('date')


% /opt/python-2.7/bin/fab -f roles.py -R mail -x host01,host02 do_date
genrating hostlists...
Excludes from cli: host01, host02
Excludes cli/file: host01, host02, x204, x404, x203, x403, x25
... done
[host01] Executing task 'do_date'
[host01] run: date
[host01] out: Thu Aug 18 15:04:44 CEST 2011
[host01] out: 
[host02] Executing task 'do_date'
[host02] run: date
[host02] out: Thu Aug 18 15:04:45 CEST 2011
[host02] out: 
[host03] Executing task 'do_date'
[host03] run: date
[host03] out: Thu Aug 18 15:04:46 CEST 2011
[host03] out: 
[host04] Executing task 'do_date'
[host04] run: date
[host04] out: Thu Aug 18 15:04:46 CEST 2011
[host04] out: 

Done.

Doh, -x ignored...

even a simple 
"/opt/python-2.7/bin/fab -f roles.py -R mailin -x x601 do_date" or 
"/opt/python-2.7/bin/fab -f roles.py -H x601 -x x601 do_date"

do not exclude the host.

It seems I don't completely get how and when hosts, exclude_hosts and roles are 
mixed to pass on to a task.

And yes, I have read the manual. Any other documentation I missed or can 
somebody offer some explanations?

Thanks in advance,
Sven


_______________________________________________
Fab-user mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/fab-user

Reply via email to