I would like to get output (and print it) of a bash command on RUNTIME (not after the command has finished).
I tried to do sometime like that but it doesn't work (because I can't combine async_status with another module):
- hosts: localhost
tasks:
- name: Run an async task
shell: while true; do echo "test" >> ~/test; done
async: 1000
poll: 0
register: cmd_result
- name: Print output of above command
async_status:
jid: "{{ cmd_result.ansible_job_id }}"
shell: cat ~/test && truncate -s 0 ~/test
register: job_result
until: job_result.finished
retries: 100
delay: 10
The last task doesn't work because there are 2 commands async_status
and shell
but it really shows what I want.
It runs a command asynchronously and then it check its status AND cat the logs of the shell command so that we can have the log output on runtime.