From 5dd2ec2cae9c929b647ebe48171e07e3dd8fcbff Mon Sep 17 00:00:00 2001 From: Daniel Hokka Zakrisson Date: Sun, 18 Nov 2012 18:40:56 +0100 Subject: [PATCH] Add a way to add directories to just one type of loader --- lib/ansible/inventory/__init__.py | 2 +- lib/ansible/utils/plugins.py | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/ansible/inventory/__init__.py b/lib/ansible/inventory/__init__.py index 3c679ba67e..12bf0ffac3 100644 --- a/lib/ansible/inventory/__init__.py +++ b/lib/ansible/inventory/__init__.py @@ -68,7 +68,7 @@ class Inventory(object): host_list = [ h for h in host_list if h and h.strip() ] else: - utils.plugins.push_basedir(self.basedir()) + utils.plugins.vars_loader.add_directory(self.basedir()) if type(host_list) == list: all = Group('all') diff --git a/lib/ansible/utils/plugins.py b/lib/ansible/utils/plugins.py index 5bc91407eb..1337ade846 100644 --- a/lib/ansible/utils/plugins.py +++ b/lib/ansible/utils/plugins.py @@ -42,6 +42,7 @@ class PluginLoader(object): self.subdir = subdir self.aliases = aliases self._module_cache = {} + self._extra_dirs = [] def _get_package_path(self): """Gets the path of a Python package""" @@ -55,7 +56,14 @@ class PluginLoader(object): """Return a list of paths to search for plugins in The list is searched in order.""" - return [os.path.join(basedir, self.subdir) for basedir in _basedirs] + self.config.split(os.pathsep) + [self._get_package_path()] + return self._extra_dirs + + [os.path.join(basedir, self.subdir) for basedir in _basedirs] + + self.config.split(os.pathsep) + + [self._get_package_path()] + + def add_directory(self, directory): + """Adds an additional directory to the search path""" + self._extra_dirs.append(directory) def find_plugin(self, name): """Find a plugin named name"""