Skip to content

Conversation

@rectalogic
Copy link

@rectalogic rectalogic commented Jan 16, 2019

Fixes #170

This seems to satisfy my use case of execute in fabric1.

Example fabric2 fabfile.py

from fabric import task
from fabric.main import program


@task(hosts=["ubuntu@playapp1", "ubuntu@playapp2"])
def uname2(c):
    print("run uname2", c.host)
    c.run("uname -a")


@task(hosts=["ubuntu@playapp2"])
def uname(c):
    print("run uname", c.host)
    c.run("uname -a")


@task
def executeme(c):
    print("run executeme task")
    program.invoke_execute(c, "uname2")
    program.invoke_execute(c, "uname")
$ fab executeme
run executeme task
('run uname2', 'playapp1')
Linux playapp1 4.15.0-1027-aws #27-Ubuntu SMP Fri Nov 2 15:14:20 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
('run uname2', 'playapp2')
Linux playapp2 4.15.0-1027-aws #27-Ubuntu SMP Fri Nov 2 15:14:20 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
('run uname', 'playapp2')
Linux playapp2 4.15.0-1027-aws #27-Ubuntu SMP Fri Nov 2 15:14:20 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

@haydenflinner
Copy link
Contributor

haydenflinner commented Jan 17, 2019

I went ahead and merged this in my extension, magicinvoke. You should be able to pip install magicinvoke over top of your current invoke install and pretend this has been merged upstream. But note that I renamed it from invoke_execute to just invoke 😃. You might also like this decorator which will allow you to enforce that parameters are in ctx by making them required parameters in the function header, rather than waiting for the eventual ctx has no such key error.

@breisig
Copy link

breisig commented Sep 18, 2019

Has this been merged yet?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Easy execution of tasks from within Python itself

3 participants