How Do I Log Task Output To A File?
[Converting my comment to an answer]

One way to do it would be to write the logs to some external file, and then having a task after it which makes use of failed_when condition, and remove the log file, if the previous task was successful.

Something like this should help you.

 - name: Run Py script
      command: &lt;&gt;.py  &gt; &lt;&gt;.log
      become: yes
      register: PyScript
      ignore_errors: True

    - name: PyScript on success
      command: rm &lt;&gt;.log
      when: PyScript|succeeded


Note: This might not be the best way to handle your problem. But, this was a hack which helped me do my logging and monitoring.