1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Generalize plugin enumeration a bit (v2)

This commit is contained in:
James Cammarata 2015-05-02 01:34:03 -05:00
parent f310d13280
commit a87d889182
3 changed files with 15 additions and 13 deletions

View file

@ -37,11 +37,9 @@ from ansible.playbook.helpers import load_list_of_blocks
from ansible.playbook.role.include import RoleInclude
from ansible.playbook.role.metadata import RoleMetadata
from ansible.playbook.taggable import Taggable
from ansible.plugins import PluginLoader
from ansible.plugins import get_all_plugin_loaders
from ansible.utils.vars import combine_vars
from ansible import plugins as ansible_plugins
__all__ = ['Role', 'ROLE_CACHE', 'hash_params']
@ -156,12 +154,11 @@ class Role(Base, Become, Conditional, Taggable):
setattr(self, 'tags', current_tags)
# dynamically load any plugins from the role directory
for name, obj in inspect.getmembers(ansible_plugins):
if isinstance(obj, PluginLoader):
if obj.subdir:
plugin_path = os.path.join(self._role_path, obj.subdir)
if os.path.isdir(plugin_path):
obj.add_directory(plugin_path)
for name, obj in get_all_plugin_loaders():
if obj.subdir:
plugin_path = os.path.join(self._role_path, obj.subdir)
if os.path.isdir(plugin_path):
obj.add_directory(plugin_path)
# load the role's other files, if they exist
metadata = self._load_role_yaml('meta')

View file

@ -20,11 +20,13 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import glob
import imp
import inspect
import os
import os.path
import sys
import glob
import imp
from ansible import constants as C
from ansible.utils.display import Display
from ansible import errors
@ -40,6 +42,9 @@ def push_basedir(basedir):
if basedir not in _basedirs:
_basedirs.insert(0, basedir)
def get_all_plugin_loaders():
return [(name, obj) for (name, obj) in inspect.getmembers(sys.modules[__name__]) if isinstance(obj, PluginLoader)]
class PluginLoader:
'''

View file

@ -30,7 +30,7 @@ from ansible.inventory.group import Group
from ansible.playbook.handler import Handler
from ansible.playbook.helpers import load_list_of_blocks
from ansible.playbook.role import ROLE_CACHE, hash_params
from ansible.plugins import module_loader, filter_loader, lookup_loader
from ansible.plugins import filter_loader, lookup_loader, module_loader
from ansible.utils.debug import debug
@ -45,9 +45,9 @@ class SharedPluginLoaderObj:
the forked processes over the queue easier
'''
def __init__(self):
self.module_loader = module_loader
self.filter_loader = filter_loader
self.lookup_loader = lookup_loader
self.module_loader = module_loader
class StrategyBase: