From d87ddb0a7ff42bdeefde5f3ec0cb788a4ff62735 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Franti=C5=A1ek=20Dvo=C5=99=C3=A1k?= <valtri@civ.zcu.cz>
Date: Mon, 22 Mar 2021 23:01:47 +0100
Subject: [PATCH] Flush progress output (for run inside terraform)

---
 orchestrate.py | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/orchestrate.py b/orchestrate.py
index 284339c..1c0f5bd 100755
--- a/orchestrate.py
+++ b/orchestrate.py
@@ -24,7 +24,7 @@ def perform_command(cmd, waitExitCode=None):
     global elapsed
 
     desc = ' '.join(map(escape_cmd, cmd))
-    print('-> %s' % desc)
+    print('-> %s' % desc, flush=True)
     start = time.perf_counter()
     if not args.dry_run:
         count = 1
@@ -33,7 +33,7 @@ def perform_command(cmd, waitExitCode=None):
             while ret is None or ret != waitExitCode:
                 time.sleep(5)
                 count += 1
-                print('->(%d) %s' % (count, desc))
+                print('->(%d) %s' % (count, desc), flush=True)
                 ret = subprocess.call(cmd)
         end = time.perf_counter()
         fperf.write('[%f] (%d) %s\n' % (end - start, count, desc))
@@ -91,7 +91,7 @@ ssh = [args.ssh] + args.ssh_opts.split(r' ')
 
 fperf = open('perf.log', buffering=1, mode='at')
 
-print('== plugin ==')
+print('== plugin ==', flush=True)
 if t and os.path.exists('deployments/%s/plugin.py' % t):
     print('-> deployments/%s/plugin.py' % t)
     plugin = importlib.import_module('deployments.%s.plugin' % t)
@@ -101,7 +101,7 @@ else:
     component = None
 
 if 'files' in args.actions:
-    print('== files ==')
+    print('== files ==', flush=True)
     print('-> hosts')
     if not args.dry_run:
         with open('hosts', 'w') as f:
@@ -147,7 +147,7 @@ ansible_ssh_common_args=\'%s -o ForwardAgent=yes -o ProxyCommand="ssh -W {{ ansi
         component.action('files')
 
 if 'ping' in args.actions:
-    print('== ping ==')
+    print('== ping ==', flush=True)
     cmd = ['ping', '-c', '1', '-i', '2', '-q', master_ip]
     perform_command(cmd, 0)
     cmd = ['ssh-keygen', '-R', master_ip]
@@ -166,7 +166,7 @@ if 'ping' in args.actions:
         component.action('ping')
 
 if 'init' in args.actions:
-    print('== init ==')
+    print('== init ==', flush=True)
 
     h = list(hosts.keys()) + ['%s.%s.' % (host, d) for host in hosts.keys()] + \
         ['%s.%s' % (host, d) for host in hosts.keys()] + list(hosts.values())
@@ -206,7 +206,7 @@ if 'init' in args.actions:
     perform_action('init', commands)
 
 if 'wait' in args.actions:
-    print('== wait ==')
+    print('== wait ==', flush=True)
     commands = [
         ['ansible', '-i', './inventory', '-m', 'command', '-a', 'uname -a', 'all'],
         ['ansible', '-i', './inventory', '-m', 'shell', '-a',
@@ -215,7 +215,7 @@ if 'wait' in args.actions:
     perform_action('wait', commands)
 
 if 'deployment' in args.actions:
-    print('== deployment ==')
+    print('== deployment ==', flush=True)
     commands = [
         ['ansible', '-i', './inventory', '-m', 'command', '-a', 'systemctl enable puppet-master',
          'master'],
-- 
GitLab