From ed3fcf9af7da58465430be4a3740c6e52d874998 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Franti=C5=A1ek=20Dvo=C5=99=C3=A1k?= <valtri@civ.zcu.cz>
Date: Wed, 30 Dec 2020 21:21:51 +0100
Subject: [PATCH] Fix the ssh keys scanning - after the /etc/hosts

---
 orchestrate.py | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/orchestrate.py b/orchestrate.py
index c9ef33c..a74b103 100755
--- a/orchestrate.py
+++ b/orchestrate.py
@@ -147,16 +147,10 @@ if 'init' in args.actions:
         # the frontend to all nodes
         ['ssh', '-o', 'ForwardAgent=yes', '%s@%s' % (user, master_ip), cycle_all]
     ]
-    for node in hosts.keys():
-        # skip the frontend - covered by the command above
-        if node == master_hostname:
-            continue
-        # the node to all nodes
-        commands += [
-            ['ssh', '-o', 'ForwardAgent=yes', '%s@%s' % (user, master_ip),
-             'ssh -o ForwardAgent=yes %s \'%s\'' % ('%s.%s' % (node, d), cycle_all)],
-        ]
     for ip in hosts.values():
+        # check the special case if it is not already frontend ('ssh-keygen -R' would be a problem)
+        if ip == master_ip:
+            continue
         commands += [
             ['ssh-keygen', '-R', ip],
             ['ssh', '-o', 'ForwardAgent=yes', '-o', 'ProxyCommand=ssh -W %s:22 -q %s@%s' %
@@ -165,6 +159,17 @@ if 'init' in args.actions:
     commands += [
         ['ansible', '-i', './inventory', '-m', 'copy', '-a', 'src=hosts dest=/etc/hosts', 'nodes'],
     ]
+    # node to node ssh keys
+    # (after the /etc/hosts is distributed)
+    for node in hosts.keys():
+        # skip the frontend - already covered
+        if node == master_hostname:
+            continue
+        # the node to all nodes
+        commands += [
+            ['ssh', '-o', 'ForwardAgent=yes', '%s@%s' % (user, master_ip),
+             'ssh -o ForwardAgent=yes %s \'%s\'' % ('%s.%s' % (node, d), cycle_all)],
+        ]
     perform_action('init', commands)
 
 if 'wait' in args.actions:
-- 
GitLab