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

Examples on how to use event_handler and status_handler #1078

Closed
Kamatam opened this issue May 18, 2022 · 4 comments · Fixed by #1086
Closed

Examples on how to use event_handler and status_handler #1078

Kamatam opened this issue May 18, 2022 · 4 comments · Fixed by #1086
Assignees
Labels
docs Changes to documentation

Comments

@Kamatam
Copy link

Kamatam commented May 18, 2022

I am trying with following python code to run the playbook using ansible_runner and ansible_runner_http but not able to find how to use event_handler and status_handler. Please suggest some example on this

import ansible_runner
from ansible_runner_http.events import event_handler
r = ansible_runner.run(private_data_dir='/tmp/ansible/,
playbook='test1.yml',
event_handler=None)

@github-actions github-actions bot added the needs_triage New item that needs to be triaged label May 18, 2022
@Akasurde
Copy link
Member

@Kamatam Thanks for reporting this issue. Could you please give us the use case of event_handler and status_handler?

@Akasurde
Copy link
Member

Akasurde commented May 18, 2022

Simplest example -

def my_event_handler(data):
    # Do something useful here
    print(data)

r = ansible_runner.run(
    host_pattern='all',
    module='ping',
    event_handler=my_event_handler,
    inventory='virtualbox.yml')

@Kamatam
Copy link
Author

Kamatam commented May 18, 2022

@Akasurde thank you for the details. My use case is to send the data to http(s) rest endpoint for specific events only instead for every event. For example, send playbook task result's events. Currently http event handler (with runner_http_url) triggers for every event.

@matburt
Copy link
Member

matburt commented May 19, 2022

What you are asking for might be a little on the complex side... what @Akasurde showed you is a basic example of how to pass the event handler in... filtering events and sending them along is a little bit more involved. The data parameter is going to contain a python dictionary and the data structure will look like this: https://ansible-runner.readthedocs.io/en/stable/intro/#artifactevents

What you want to do is filter on the event type you are looking for ... we document this a little bit in the AWX architecture documentation: https://github.com/ansible/awx/blob/devel/docs/job_events.md#job-event-relationships

Which makes use of Runner behind the scenes.

You can modify the existing http plugin to do what you want and use yours instead of the http plugin.

@Akasurde Akasurde removed the needs_triage New item that needs to be triaged label May 31, 2022
@Akasurde Akasurde self-assigned this May 31, 2022
@Akasurde Akasurde added the docs Changes to documentation label May 31, 2022
Akasurde added a commit to Akasurde/ansible-runner that referenced this issue Jun 1, 2022
Fixes: ansible#1078

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
Shrews pushed a commit that referenced this issue Jun 1, 2022
Fixes: #1078

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
Akasurde added a commit to Akasurde/ansible-runner that referenced this issue Jun 6, 2022
…dler

Fixes: ansible#1078

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
Akasurde added a commit to Akasurde/ansible-runner that referenced this issue Jun 6, 2022
…dler

Fixes: ansible#1078

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
Shrews pushed a commit that referenced this issue Jun 6, 2022
…dler (#1091)

Fixes: #1078

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
Shrews pushed a commit that referenced this issue Jun 6, 2022
…dler (#1092)

Fixes: #1078

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Changes to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants