Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiple tasks in a group_task #8

Closed
dbarrosop opened this issue Nov 25, 2017 · 1 comment
Closed

multiple tasks in a group_task #8

dbarrosop opened this issue Nov 25, 2017 · 1 comment

Comments

@dbarrosop
Copy link
Contributor

dbarrosop commented Nov 25, 2017

Brigade supports grouping tasks. For instance, you can do something like:

def print_facts(task, facts):
    r1 = networking.napalm_get_facts(task, "facts")
    print(r1)
    r2 = networking.napalm_get_facts(task, "interfaces")
    print(r2)
    return ???


brigade.run(task=get_facts,
                    facts=facts)

The idea is to group tasks that logically go together to build reusable workflows. The challenge is what to return in the case you may want to return something or pass it to a "callback" (see #3). What I propose is to have a MultiResult class that does something like:

class MultiResult(object):
    
    def __init__(self, *results):
        self.results = results
        self.changed = any([r.changed for r in result])

You'd basically rewrite the grouping above like this:

def print_facts(task, facts):
    r1 = networking.napalm_get_facts(task, "facts")
    r2 = networking.napalm_get_facts(task, "interfaces")
    return MultiResult(r1, r2)
@dbarrosop
Copy link
Contributor Author

Implemented.

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

No branches or pull requests

1 participant