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.
This commit is contained in:
Thomas Woerner
2019-07-29 13:03:24 +02:00
parent 781ac6e90b
commit ab25078b47
3 changed files with 15 additions and 9 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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