diff --git a/jinja2cli/cli.py b/jinja2cli/cli.py index 5ab46bf..7aa2579 100644 --- a/jinja2cli/cli.py +++ b/jinja2cli/cli.py @@ -221,9 +221,21 @@ def _parse_env(data): def _load_ansible_filters(): - from ansible.plugins.filter.core import FilterModule + from pkgutil import iter_modules + from jinja2.utils import import_string - return FilterModule().filters() + try: + import ansible.plugins.filter + except ImportError: + print("This feature requires the `ansible-core` package.") + raise + + filters = dict() + for module in iter_modules(ansible.plugins.filter.__path__): + filter_module = import_string(f"ansible.plugins.filter.{module.name}") + filters.update(filter_module.FilterModule().filters()) + + return filters def render(template_path, data, extensions, strict=False, ansible=False):