Fabric: Fabric 2 - Execute a task on a Group (with arguments)

Created on 8 Dec 2017  ·  5Comments  ·  Source: fabric/fabric

I've got a task that has arguments. I'd like to run this task on a group of hosts, with a different argument to the task depending on the host, from within another Python script.

The comment within execute says to implement it as per the tutorial. Can I get a link to this tutorial? And if I get it working /get it working with arguments being passed through, would this be a welcome pull request?

Feature Group

Most helpful comment

This feature is greatly needed for Fabric2. Any idea when it will be merged?

All 5 comments

I think this is the closest thing to a Fabric 2 tutorial: http://docs.fabfile.org/en/stable/getting_started.html

I'd like to run this task on a group of hosts, with a different argument to the task depending on the host, from within another Python script.

Not knowing your exact use case, and noting that Group isn't super well fleshed out yet (focus has been on getting Connection in good shape), I'll point out that _so far_, Group has been conceived as a convenience/wrapper API only - it's the common case of "I give you a list of hostnames and a thing to do and you do it for me, without me having to write my own loop."

For anything more complex, the idea is it should still be quite easy to do it yourself using manually-instantiated Connections within whatever Python construct fits your use case (iterating, etc.) So in this case, you'd have a 'meta' task performing something like for hostname, kwargs in my_map_of_hostnames_to_kwargs.items(): othertask(Connection(hostname), **kwargs).

(That still leaves pyinvoke/invoke#170, or less likely, #4, but for now both of those are work-aroundable.)

If you supply details about the use case, maybe one of us can elaborate further.


Re: tutorial: yea the 'getting started' page is the tutorial, the specific bit that pretends to know about Group.execute is http://docs.fabfile.org/en/v2/getting_started.html#bringing-it-all-together - but as above, the behavior isn't really thought out yet!

Thank you so much for this v2 tutorial. I had found the source of it on GitHub but neglected to read around it.

cxn = Connection(host) is the critical bit I was missing; the parts of the tutorial I had found made no mention of what cxn was, and I didn't dig enough to figure out it was just a Connection.

I've already written the code that I needed when I posted this using the Fabric3 port, but with a mind towards moving to v2 once it's on PyPi. Thanks for your time guys!

Edit: It might help future potential users if you added a link to that v2 tutorial into the README here. I'd pull request it but that seems like a bit much for a one line change :p

Can't the host be automatically loaded from the fabric.json config file instead of passing it to the -D argument on the command line?

This feature is greatly needed for Fabric2. Any idea when it will be merged?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kaangoksal picture kaangoksal  ·  11Comments

ajmcateer picture ajmcateer  ·  18Comments

hyperknot picture hyperknot  ·  21Comments

alexvicegrab picture alexvicegrab  ·  22Comments

kuba-baku picture kuba-baku  ·  11Comments