EX294 Transform data with filters and plugins Practice Question
A developer wrote a custom filter plugin in a Python file `my_filters.py` and placed it in the directory `./filter_plugins/`. The playbook fails with 'ERROR! no filter named 'my_custom_filter''. The playbook is located in `/home/user/project/playbook.yml`. The `ansible.cfg` file in the same directory does not set `filter_plugins`. Which is the most likely cause?
⚠ Common exam trap
Red Hat often tests the misconception that the filter function name must match the class name or that the file must be named `__init__.py`, when in fact the critical requirement is the `FilterModule` class with a `filters()` method.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
The plugin file must be a Python module with a class named `FilterModule` and the filter function must be listed in the `filters` method
Ansible requires custom filter plugins to be Python modules that define a class named `FilterModule` with a `filters()` method returning a dictionary mapping filter names to their implementing functions. Without this structure, Ansible cannot discover or register the filter, causing the 'no filter named' error.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
The filter file must be named `__init__.py`
Why it's wrong here
Ansible loads every .py file in filter_plugins/ as a module; __init__.py is only needed to make a directory a Python package, which Ansible does not require here. It is tempting because Python packages conventionally use __init__.py, and that would be correct if the plugins were imported as a package rather than loaded by path.
- ✓
The plugin file must be a Python module with a class named `FilterModule` and the filter function must be listed in the `filters` method
Why this is correct
Ansible loads filter plugins only from Python modules exposing a FilterModule class whose filters method returns a dict mapping filter names to callables. Without that structure, the plugin is ignored, so no filter named my_custom_filter is registered, producing the error.
- ✗
The filter function must be imported in the playbook via `filter_plugins: my_filters`
Why it's wrong here
filter_plugins is an ansible.cfg or play-level keyword pointing to a directory, not a playbook import statement for individual files. It is tempting because importing a module by name is standard Python practise, and that would be correct if the filter were a library consumed inside a module_utils or action plugin rather than a filter plugin.
- ✗
The filter function name does not match the class name in the plugin
Why it's wrong here
Filter plugins expose plain functions in a FilterModule mapping; there is no class-name matching requirement as there is for, say, lookup or callback plugins. It is tempting because many Ansible plugin types do tie the class name to the plugin name, and that rule would be correct for a callback plugin registered by its class.
Go deeper
Related to this question
About these practice questions
Courseiva writes every EX294 question from scratch — 392 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This EX294 practice question is part of Courseiva's free Red Hat certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the EX294 exam.