2

I use ansible runner to trigger an ansible-playbook from a django application, which runs fine. See the following code.

import ansible_runner

def runner(request):
    r = ansible_runner.run_async(private_data_dir='/Users/path/to/private_dir', 
                                 playbook='path/to/provision.yml')

What I am trying to do is provide a live update (The stdout of each of the ansible tasks running inside that playbook) to the user whenever a deployment is happening on his project.

As of now, I can see the stdout instantly in the console. But I am not able to figure out how can I read the stdout interactively/instantly from ansible runner.

I can wait for the task to finish and finally read the final stdout and display it to the user, which I think is not a better user experience. I would like to provide a live update on the play which is happening to the user. similar to you see on travis-ci builds. So far I am not able to figure out anything from the docs of ansible-runner.

I tried inspecting the output of r.events like below

r = ansible_runner.run_async(private_data_dir='/Users/path/to/private_dir', 
                                 playbook='path/to/provision.yml')
for event in r[1].events:
   try:
     print(event['event_data']['task'])
   except KeyError:
     pass
 
 # where r[1] is the Runner object returned by ansible, 
 # r[0] is the thread which runs ansible

so basically this r[1] is a generator object but when the loop runs it only prints a few lines from the starting point, I assume that's because the task is not yet completed, so the generator is also not populated yet.

What are your suggestions or links that can point me in the right direction? Feel free to ask for any clarification. Greatly appreciate the help :)

Community
  • 1
  • 1
Shobi
  • 10,374
  • 6
  • 46
  • 82
  • How are you triggering the playbook execution? And how does your app respond back to the user when the playbook is finished? Have you tried using the HTTP Status/Event Emitter Plugin as described in the documentation? – PanosVl Jan 13 '20 at 12:05

0 Answers0