From ab25078b471ad252319f0fd49914971df2a17b92 Mon Sep 17 00:00:00 2001
From: Thomas Woerner <twoerner@redhat.com>
Date: Mon, 29 Jul 2019 13:03:24 +0200
Subject: [PATCH] ansible-ipa-*-install: Get continuous output working for
 python2 also

The used code for continuous output from the ansible-playbook call was
only working for Python2. The output has only been printed when the command
finised. This code has been replaced with code that is working with Python2
and Python3.
---
 utils/ansible-ipa-client-install  | 8 +++++---
 utils/ansible-ipa-replica-install | 8 +++++---
 utils/ansible-ipa-server-install  | 8 +++++---
 3 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/utils/ansible-ipa-client-install b/utils/ansible-ipa-client-install
index de78b32d..453b75f3 100755
--- a/utils/ansible-ipa-client-install
+++ b/utils/ansible-ipa-client-install
@@ -227,9 +227,11 @@ def run_cmd(args):
         p = subprocess.Popen(args, stdout=p_out, stderr=p_err,
                              close_fds=True, bufsize=1,
                              universal_newlines=True)
-        with p.stdout:
-            for line in p.stdout:
-                sys.stdout.write(line)
+        while True:
+            line = p.stdout.readline()
+            if p.poll() is not None and line == "":
+                break
+            sys.stdout.write(line)
     except KeyboardInterrupt:
         p.wait()
         raise
diff --git a/utils/ansible-ipa-replica-install b/utils/ansible-ipa-replica-install
index 1d131253..54c85bb4 100755
--- a/utils/ansible-ipa-replica-install
+++ b/utils/ansible-ipa-replica-install
@@ -295,9 +295,11 @@ def run_cmd(args):
         p = subprocess.Popen(args, stdout=p_out, stderr=p_err,
                              close_fds=True, bufsize=1,
                              universal_newlines=True)
-        with p.stdout:
-            for line in p.stdout:
-                sys.stdout.write(line)
+        while True:
+            line = p.stdout.readline()
+            if p.poll() is not None and line == "":
+                break
+            sys.stdout.write(line)
     except KeyboardInterrupt:
         p.wait()
         raise
diff --git a/utils/ansible-ipa-server-install b/utils/ansible-ipa-server-install
index e1ab3d4d..9e2ea486 100755
--- a/utils/ansible-ipa-server-install
+++ b/utils/ansible-ipa-server-install
@@ -331,9 +331,11 @@ def run_cmd(args):
         p = subprocess.Popen(args, stdout=p_out, stderr=p_err,
                              close_fds=True, bufsize=1,
                              universal_newlines=True)
-        with p.stdout:
-            for line in p.stdout:
-                sys.stdout.write(line)
+        while True:
+            line = p.stdout.readline()
+            if p.poll() is not None and line == "":
+                break
+            sys.stdout.write(line)
     except KeyboardInterrupt:
         p.wait()
         raise
-- 
GitLab