diff options
author | James Cammarata <jimi@sngx.net> | 2016-02-19 09:53:36 -0500 |
---|---|---|
committer | James Cammarata <jimi@sngx.net> | 2017-01-27 12:01:14 -0600 |
commit | e04b83b600f89ca98e86cbdbaa790bc88c647dc2 (patch) | |
tree | 5110761c6092c24a62ef7c65a1569975adaa4f73 /lib/ansible/plugins/__init__.py | |
parent | ad83756b48e88f443bbf8363b6a9267bae07973c (diff) | |
download | ansible-e04b83b600f89ca98e86cbdbaa790bc88c647dc2.tar.gz |
Make module_utils a plugin to support local module_utilsmodule_utils_commmon_loading
Diffstat (limited to 'lib/ansible/plugins/__init__.py')
-rw-r--r-- | lib/ansible/plugins/__init__.py | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/lib/ansible/plugins/__init__.py b/lib/ansible/plugins/__init__.py index 25152bfc00..5eb036ed43 100644 --- a/lib/ansible/plugins/__init__.py +++ b/lib/ansible/plugins/__init__.py @@ -31,6 +31,7 @@ import warnings from collections import defaultdict from ansible import constants as C +from ansible.compat.six import string_types from ansible.module_utils._text import to_text @@ -173,7 +174,11 @@ class PluginLoader: if self.config is not None: for path in self.config: path = os.path.realpath(os.path.expanduser(path)) - contents = glob.glob("%s/*" % path) + glob.glob("%s/*/*" % path) + contents = [] + # FIXME: arbitrary 10 deep here, should probably walk() to find files + # instead so we don't run into future problems. + for i in range(1, 10): + contents += glob.glob("%s/%s" % (path, '/*' * i)) for c in contents: if os.path.isdir(c) and c not in ret: ret.append(c) @@ -270,6 +275,21 @@ class PluginLoader: except IndexError: extension = '' + + if isinstance(name, tuple): + dir_parts = list(reversed(os.path.dirname(full_path).split(os.sep) + [base_name])) + match = True + for idx, part in enumerate(reversed(name)): + if part != dir_parts[idx]: + match = False + break + if not match: + continue + if name not in self._plugin_path_cache['']: + self._plugin_path_cache[''][name] = full_path + if name not in self._plugin_path_cache[extension]: + self._plugin_path_cache[extension][name] = full_path + # Module found, now enter it into the caches that match # this file if base_name not in self._plugin_path_cache['']: @@ -284,7 +304,7 @@ class PluginLoader: if full_name not in self._plugin_path_cache[extension]: self._plugin_path_cache[extension][full_name] = full_path - self._searched_paths.add(path) + #self._searched_paths.add(path) try: return pull_cache[name] except KeyError: @@ -293,7 +313,7 @@ class PluginLoader: pass # if nothing is found, try finding alias/deprecated - if not name.startswith('_'): + if isinstance(name, string_types) and not name.startswith('_'): alias_name = '_' + name # We've already cached all the paths at this point if alias_name in pull_cache: @@ -466,6 +486,13 @@ module_loader = PluginLoader( 'library', ) +module_utils_loader = PluginLoader( + '', + 'ansible.module_utils', + 'module_utils', + 'module_utils', +) + lookup_loader = PluginLoader( 'LookupModule', 'ansible.plugins.lookup', |