summaryrefslogtreecommitdiff
path: root/lib/ansible/plugins/__init__.py
diff options
context:
space:
mode:
authorBrian Coca <brian.coca+git@gmail.com>2016-04-07 10:16:35 -0400
committerBrian Coca <brian.coca+git@gmail.com>2016-04-07 10:16:35 -0400
commit5225048df921175e67a4681788ce76d4368786a1 (patch)
tree592f353ba0ad8ace8fe0f7defeccea114eceb7ce /lib/ansible/plugins/__init__.py
parentfd9838f1a0b2cef54b9ba84df6db03248e7d5c58 (diff)
downloadansible-5225048df921175e67a4681788ce76d4368786a1.tar.gz
capture attribute errors for invalid class plugins
also switched to py3 safe to_str
Diffstat (limited to 'lib/ansible/plugins/__init__.py')
-rw-r--r--lib/ansible/plugins/__init__.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/ansible/plugins/__init__.py b/lib/ansible/plugins/__init__.py
index 03558df986..14fc20fb9e 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.utils.unicode import to_str
try:
from __main__ import display
@@ -247,7 +248,7 @@ class PluginLoader:
try:
full_paths = (os.path.join(path, f) for f in os.listdir(path))
except OSError as e:
- display.warning("Error accessing plugin paths: %s" % str(e))
+ display.warning("Error accessing plugin paths: %s" % to_str(e))
for full_path in (f for f in full_paths if os.path.isfile(f) and not f.endswith('__init__.py')):
full_name = os.path.basename(full_path)
@@ -354,7 +355,7 @@ class PluginLoader:
class_only = kwargs.pop('class_only', False)
all_matches = []
-
+
for i in self._get_paths():
all_matches.extend(glob.glob(os.path.join(i, "*.py")))
@@ -366,7 +367,11 @@ class PluginLoader:
if path not in self._module_cache:
self._module_cache[path] = self._load_module_source(name, path)
- obj = getattr(self._module_cache[path], self.class_name)
+ try:
+ obj = getattr(self._module_cache[path], self.class_name)
+ except AttributeError as e:
+ display.warning("Skipping plugin (%s) as it seems to be invalid: %s" % (path, to_str(e)))
+
if self.base_class:
# The import path is hardcoded and should be the right place,
# so we are not expecting an ImportError.