Source: ansible
Version: 2.9.6+dfsg-1~bpo10+1
Severity: normal

Dear Maintainer,

Using ansible-pull command from a virtual machine console works but
the progression of the work done is not displayed live. It is buffered
(4kio ?) and bunch of text appears at once, "too late".

It shows up also via ssh but with a less big buffer (less annoying, but
happens too).

For me it affects current buster and current buster-backports. I didn't
see any clue upstream about solving this issue. I just report it here
for now.

I expect that the output should be live as when using ansible-playbook.
Code appears to handle that. strace shows up many unbuffered read from
forked ansible commands, but only a few big writes to terminal.

Please find attached a patch that works for me on 2.9 and 2.7. I suspect
that is an upstream that may be distro-agnotic bug but I didn't tried it
elsewhere right now.

diff --git a/ansible/utils/cmd_functions.py b/ansible/utils/cmd_functions.py
index 7a0fb23..ef6cb14 100644
--- a/ansible/utils/cmd_functions.py
+++ b/ansible/utils/cmd_functions.py
@@ -57,6 +57,7 @@ def run_cmd(cmd, live=False, readsize=10):
                     sys.stdout.buffer.write(dat)
                 else:
                     sys.stdout.write(dat)
+                sys.stdout.flush()
             stdout += dat
             if dat == b'':
                 rpipes.remove(p.stdout)
@@ -69,6 +70,7 @@ def run_cmd(cmd, live=False, readsize=10):
                     sys.stdout.buffer.write(dat)
                 else:
                     sys.stdout.write(dat)
+                sys.stdout.flush()
             if dat == b'':
                 rpipes.remove(p.stderr)
         # only break out if we've emptied the pipes, or there is nothing to

I may have tested onnly 1 code path of the two that are patched above. I am
unclear about python 2/3 mixing and ansible on Debian 10.

-- System Information:
Debian Release: 10.8
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 5.9.0-0.bpo.5-amd64 (SMP w/2 CPU cores)
Kernel taint flags: TAINT_OOT_MODULE
Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8), 
LANGUAGE=fr_FR.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled
diff --git a/ansible/utils/cmd_functions.py b/ansible/utils/cmd_functions.py
index 7a0fb23..ef6cb14 100644
--- a/ansible/utils/cmd_functions.py
+++ b/ansible/utils/cmd_functions.py
@@ -57,6 +57,7 @@ def run_cmd(cmd, live=False, readsize=10):
                     sys.stdout.buffer.write(dat)
                 else:
                     sys.stdout.write(dat)
+                sys.stdout.flush()
             stdout += dat
             if dat == b'':
                 rpipes.remove(p.stdout)
@@ -69,6 +70,7 @@ def run_cmd(cmd, live=False, readsize=10):
                     sys.stdout.buffer.write(dat)
                 else:
                     sys.stdout.write(dat)
+                sys.stdout.flush()
             if dat == b'':
                 rpipes.remove(p.stderr)
         # only break out if we've emptied the pipes, or there is nothing to

Reply via email to