So I think I understand why Fabric works this way, and I'd like to
see the docs updated for the next poor sap who tries to be clever like
me :-)

Given the following fabfile:

    from fabric.api import *
    env.hosts = ['hostA']

    def withEnv():
        run('/bin/true')

    def paramNo(hostname):
        env.hosts = [hostname]
        run('/bin/true')

    def paramYes(hostname):
        env.host_string = hostname
        run('/bin/true')


Why does paramNo not do what I expect?  (fab output trimmed:)

    $ fab withEnv
    [hostA] run: /bin/true

    $ fab paramNo:hostB
    [hostA] run: /bin/true

    $ fab paramYes:hostB
    [hostB] run: /bin/true


I think that the answer is that Fabric loops over env.hosts, setting
env.host_string inside the invoked function.  Assigning to hosts.env
within a function will have no effect on where put(), run()
et.al. runs (but possibly upon subsequent turns of the loop?) since
env.host_string is already set.  Am I understanding correctly?  Can I
contribute a simple patch to the docs without monkeying around with
git?

Fabric is awesome, thanks!


-- 
Christopher DeMarco <[email protected]>
IT Director
MAYA Group
+1-412-708-9660



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

Reply via email to