diff --git a/lib/ansible/utils/plugins.py b/lib/ansible/utils/plugins.py index 09aaa5b3ba..faf5b5f26f 100644 --- a/lib/ansible/utils/plugins.py +++ b/lib/ansible/utils/plugins.py @@ -94,10 +94,8 @@ class PluginLoader(object): m = __import__(self.package) parts = self.package.split('.')[1:] self.package_path = os.path.join(os.path.dirname(m.__file__), *parts) - paths.extend(self._all_directories(self.package_path)) - return paths - else: - return [ self.package_path ] + paths.extend(self._all_directories(self.package_path)) + return paths def _get_paths(self): ''' Return a list of paths to search for plugins in ''' @@ -105,8 +103,7 @@ class PluginLoader(object): if self._paths is not None: return self._paths - ret = [] - ret += self._extra_dirs + ret = self._extra_dirs[:] for basedir in _basedirs: fullpath = os.path.realpath(os.path.join(basedir, self.subdir)) if os.path.isdir(fullpath): @@ -139,11 +136,9 @@ class PluginLoader(object): # look for any plugins installed in the package subtree ret.extend(self._get_package_paths()) - package_dirs = self._get_package_paths() - + # cache and return the result self._paths = ret - return ret @@ -156,7 +151,9 @@ class PluginLoader(object): if with_subdir: directory = os.path.join(directory, self.subdir) if directory not in self._extra_dirs: + # append the directory and invalidate the path cache self._extra_dirs.append(directory) + self._paths = None def find_plugin(self, name, suffixes=None, transport=''): ''' Find a plugin named name ''' diff --git a/test/integration/non_destructive.yml b/test/integration/non_destructive.yml index 619396acb2..b177763fbf 100644 --- a/test/integration/non_destructive.yml +++ b/test/integration/non_destructive.yml @@ -38,3 +38,5 @@ - { role: test_script, tags: test_script } - { role: test_authorized_key, tags: test_authorized_key } - { role: test_get_url, tags: test_get_url } + - { role: test_embedded_module, tags: test_embedded_module } + diff --git a/test/integration/roles/test_embedded_module/library/test_integration_module b/test/integration/roles/test_embedded_module/library/test_integration_module new file mode 100644 index 0000000000..5af29b4c01 --- /dev/null +++ b/test/integration/roles/test_embedded_module/library/test_integration_module @@ -0,0 +1,3 @@ +#!/usr/bin/env python + +print '{"changed":false, "msg":"this is the embedded module"}' diff --git a/test/integration/roles/test_embedded_module/tasks/main.yml b/test/integration/roles/test_embedded_module/tasks/main.yml new file mode 100644 index 0000000000..6a6d6485fc --- /dev/null +++ b/test/integration/roles/test_embedded_module/tasks/main.yml @@ -0,0 +1,9 @@ +- name: run the embedded dummy module + test_integration_module: + register: result + +- name: assert the embedded module ran + assert: + that: + - "'msg' in result" + - result.msg == "this is the embedded module"