title: How to read the events from ansible runner programatically
body: <p>I use <a href="https://github.com/ansible/ansible-runner" rel="nofollow noreferrer">ansible runner</a> to trigger an ansible-playbook from a django application, which runs fine. See the following code.</p>
  <pre><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')
  </code></pre>
  <p>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.</p>
  <p><strong>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.</strong></p>
  <p>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.</p>
  <p>I tried inspecting the output of <code>r.events</code> like below</p>
  <pre><code>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
  </code></pre>
  <p>so basically this <code>r[1]</code> 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.</p>
  <p>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 :)</p>