Revert "Revert "Enabled host_key_checking""

This reverts commit 3bc31c889b86ce9b1acefde94db5e3e8b53939be.

Change-Id: Id8d5ae3d8bd764865ca89efb8926e80f1fcbb6a4
diff --git a/zuul/launcher/ansiblelaunchserver.py b/zuul/launcher/ansiblelaunchserver.py
index a9b9733..7061e71 100644
--- a/zuul/launcher/ansiblelaunchserver.py
+++ b/zuul/launcher/ansiblelaunchserver.py
@@ -105,6 +105,7 @@
         self.root = tempfile.mkdtemp()
         self.ansible_root = os.path.join(self.root, 'ansible')
         os.makedirs(self.ansible_root)
+        self.known_hosts = os.path.join(self.ansible_root, 'known_hosts')
         self.inventory = os.path.join(self.ansible_root, 'inventory')
         self.playbook = os.path.join(self.ansible_root, 'playbook')
         self.post_playbook = os.path.join(self.ansible_root, 'post_playbook')
@@ -1147,11 +1148,17 @@
             parameters[timeout_var] = str(timeout * 1000)
 
         with open(jobdir.playbook, 'w') as playbook:
+            pre_tasks = []
             tasks = []
             main_block = []
             error_block = []
             variables = []
 
+            shellargs = "ssh-keyscan %s > %s" % (
+                self.host, jobdir.known_hosts)
+            pre_tasks.append(dict(shell=shellargs,
+                             delegate_to='127.0.0.1'))
+
             tasks.append(dict(block=main_block,
                               rescue=error_block))
 
@@ -1185,7 +1192,7 @@
 
             variables.append(dict(timeout=timeout))
             play = dict(hosts='node', name='Job body', vars=variables,
-                        tasks=tasks)
+                        pre_tasks=pre_tasks, tasks=tasks)
             playbook.write(yaml.safe_dump([play], default_flow_style=False))
 
         early_publishers, late_publishers = self._transformPublishers(jjb_job)
@@ -1218,7 +1225,6 @@
         with open(jobdir.config, 'w') as config:
             config.write('[defaults]\n')
             config.write('hostfile = %s\n' % jobdir.inventory)
-            config.write('host_key_checking = False\n')
             config.write('keep_remote_files = True\n')
             config.write('local_tmp = %s/.ansible/tmp\n' % jobdir.root)
             config.write('private_key_file = %s\n' % self.private_key_file)
@@ -1229,6 +1235,11 @@
             config.write('callback_plugins = %s\n' % self.callback_dir)
             config.write('library = %s\n' % self.library_dir)
 
+            config.write('[ssh_connection]\n')
+            ssh_args = "-o ControlMaster=auto -o ControlPersist=60s " \
+                "-o UserKnownHostsFile=%s" % jobdir.known_hosts
+            config.write('ssh_args = %s\n' % ssh_args)
+
         return timeout
 
     def _ansibleTimeout(self, proc, msg):