Ansible display realtime shell stdout
"Real time" or "streaming" output has not been merged to Ansible yet. The original issue was closed in 2014 as not feasible. A more recent proposal has no major updates since February 2018.
This is not available for users of Ansible. It will require serious hacking, and more importantly testing, on command and callback plugins to work as proposed.
Bonus playbook review: Your example command can be done by the apt module. This has more features than calling apt command line yourself.
- name: Only run "apt-get update" if the last one is more than 3600 seconds ago
apt:
update_cache: yes
cache_valid_time: 3600
Related videos on Youtube
Veerendra
Updated on September 18, 2022Comments
-
Veerendra over 1 year
I want see the realtime
shell
stdout, instead ofregister
ing in a variable and then display once it is completed.Example Playbook -
test.yml
- name: Testing RUN Shell Command hosts: localhost connection: local tasks: - name: Runnig Update shell: apt update
Default Output
$ ansible-playbook test.yml PLAY [Testing RUN Shell Command] ****************************************************************************************************** TASK [Gathering Facts] **************************************************************************************************************** ok: [localhost] TASK [Runnig Update] ****************************************************************************************************************** changed: [localhost] PLAY RECAP **************************************************************************************************************************** localhost : ok=2 changed=1 unreachable=0 failed=0
But I want to see what it is doing like when we run the
apt update
in terminal$ sudo apt update Ign:1 http://dl.google.com/linux/chrome/deb stable InRelease Hit:2 http://dl.google.com/linux/chrome/deb stable Release Hit:3 http://ppa.launchpad.net/brightbox/ruby-ng/ubuntu bionic InRelease Get:4 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB] Hit:6 http://in.archive.ubuntu.com/ubuntu bionic InRelease Hit:7 http://ppa.launchpad.net/canonical-chromium-builds/stage/ubuntu bionic InRelease ------OUTPUT REMOVED----------
I see that there is already discussion going on at github issue and look like that is not possible.
Is there any trick get the realtime stdout with help ansible Callback?