Extract ansible library file copying to a function

The logic here has grown enough that a series of copypasta is now fairly
beefy. Not that beef in pasta is bad or anything, but maybe let's do a
utility function.

Change-Id: Ibd91acac936f3dd52ccd57816de167e1487499ed
diff --git a/zuul/executor/server.py b/zuul/executor/server.py
index 71b643a..9a3c1d4 100644
--- a/zuul/executor/server.py
+++ b/zuul/executor/server.py
@@ -219,6 +219,16 @@
             self.condition.release()
 
 
+def _copy_ansible_files(python_module, target_dir):
+        library_path = os.path.dirname(os.path.abspath(python_module.__file__))
+        for fn in os.listdir(library_path):
+            full_path = os.path.join(library_path, fn)
+            if os.path.isdir(full_path):
+                shutil.copytree(full_path, os.path.join(target_dir, fn))
+            else:
+                shutil.copy(os.path.join(library_path, fn), target_dir)
+
+
 class ExecutorServer(object):
     log = logging.getLogger("zuul.ExecutorServer")
 
@@ -286,40 +296,10 @@
         if not os.path.exists(self.lookup_dir):
             os.makedirs(self.lookup_dir)
 
-        library_path = os.path.dirname(os.path.abspath(
-            zuul.ansible.library.__file__))
-        for fn in os.listdir(library_path):
-            full_path = os.path.join(library_path, fn)
-            if os.path.isdir(full_path):
-                shutil.copytree(full_path, os.path.join(self.library_dir, fn))
-            else:
-                shutil.copy(os.path.join(library_path, fn), self.library_dir)
-        action_path = os.path.dirname(os.path.abspath(
-                                      zuul.ansible.action.__file__))
-        for fn in os.listdir(action_path):
-            full_path = os.path.join(action_path, fn)
-            if os.path.isdir(full_path):
-                shutil.copytree(full_path, os.path.join(self.action_dir, fn))
-            else:
-                shutil.copy(full_path, self.action_dir)
-
-        callback_path = os.path.dirname(os.path.abspath(
-            zuul.ansible.callback.__file__))
-        for fn in os.listdir(callback_path):
-            full_path = os.path.join(callback_path, fn)
-            if os.path.isdir(full_path):
-                shutil.copytree(full_path, os.path.join(self.callback_dir, fn))
-            else:
-                shutil.copy(os.path.join(callback_path, fn), self.callback_dir)
-
-        lookup_path = os.path.dirname(os.path.abspath(
-            zuul.ansible.lookup.__file__))
-        for fn in os.listdir(lookup_path):
-            full_path = os.path.join(lookup_path, fn)
-            if os.path.isdir(full_path):
-                shutil.copytree(full_path, os.path.join(self.lookup_dir, fn))
-            else:
-                shutil.copy(os.path.join(lookup_path, fn), self.lookup_dir)
+        _copy_ansible_files(zuul.ansible.library, self.library_dir)
+        _copy_ansible_files(zuul.ansible.action, self.action_dir)
+        _copy_ansible_files(zuul.ansible.callback, self.callback_dir)
+        _copy_ansible_files(zuul.ansible.lookup, self.lookup_dir)
 
         self.job_workers = {}