I have Problems with self written filter_plugins that worked flawlessly in the past.
I’m executing ansible playbooks via gitlab-runner in our infrastructure. In the past we used a runner of type shell. Some roles use additional filter plugins that are provided via rolename/filter_plugins/myfilter.py which worked as intended with ansible 2.17.
At the moment I’m implementing a new runner that uses docker container with ansible 2.20 which works the same but uses a different folder structure and a newer ansible version. The playbooks and roles didn’t change.
when executing the playbook the task that uses a filter_plugin from testrole/filter_plugins/myfilter.py wont load the plugin and errors out.
Even setting ANSIBLE_FILTER_PLUGINS to the directory or copying the plugin to /usr/lib/python3/dist…/plugins/filter doesn’t work. Setting ANSIBLE_DEBUG=1 I see that ansible doesn’t even attempt to load the plugin.
Any Ideas why this doesn’t work any longer? Does anything regarding filter plugins changed in versions > 2.17?
Documentation states that nothing changed in that part:
Quote:
To use a standalone plugin only in a single role, store the plugin in a subdirectory for the correct plugin_type (for example, cache_plugins or strategy_plugins) within that role. When shipped as part of a role, the plugin is available as soon as the role is executed. These directories must use the _plugins suffix. For a full list of plugin types, see Working with plugins.
Could it be that you are using the newer Python version and your plugin is not compatible with it? Maybe Ansible is just not reporting failed plugin imports so you don’t see the real reason it skipped the plugin.
both runner are using python3.12 and are bookworm based. the docker container uses the baseimage python3.12-slim-bookworm. There should be no difference in the python version, as far as i can tell.
the filter plugin is stored inside the role and has worked the last 2 years without a problem:
rolename/filter_plugins/myfilter.py
I’m out of ideas. The biggest difference is that the container uses an ansible version installed via pip, the old shell runner the debian apt package. maybe im missing some dependencies?
Found the error, must have missed it in previous runs:
[WARNING]: Skipping plugin (/builds/ansible/playbooks/infrastructure/network/exos/exos_configure_ntp/filter_plugins/exos_filter.py), cannot load: cannot import name ‘passlib_or_crypt’ from ‘ansible.utils.encrypt’ (/usr/local/lib/python3.12/site-packages/ansible/utils/encrypt.py)
[WARNING]: Skipping plugin (/builds/ansible/playbooks/infrastructure/network/exos/exos_configure_ntp/roles/exos_facts/filter_plugins/exos_filter.py), cannot load: cannot import name ‘passlib_or_crypt’ from ‘ansible.utils.encrypt’ (/usr/local/lib/python3.12/site-packages/ansible/utils/encrypt.py)
The plugin started as a copy of the vlan_parser plugin and tried to import passlib_or_crypt for whatever reason, which was not available. Instead of fixing the dependency error I just removed the import since that module was never used in the filter anyway.