Interview Prep/Ansible/Roles, Collections and Galaxy

`template error while templating string: No filter named 'to_slug'` for your team's own filter

AdvancedTroubleshootingRoles, Collections and Galaxy
Answer

Likely causes →

  • The plugin lives in filter_plugins/ next to an old playbook location, but the playbook moved.
  • The plugin is in a role's filter_plugins/, and that role is not part of this play.
  • The plugin is in a collection but is called without its FQCN.
  • The Python file has a syntax error, so the plugin silently fails to load (visible with -vvvv).

Diagnose →

ansible-doc -t filter -l | grep -i slug
ANSIBLE_FILTER_PLUGINS=./filter_plugins ansible localhost -m debug -a "msg={{ 'A B' | to_slug }}" -vvvv

Fix → Ship custom plugins in a collection and call them as acme.utils.to_slug, or set filter_plugins = ./plugins/filter in ansible.cfg.

Prevent → Keep custom plugins in a versioned collection with tests (ansible-test units).

All Ansible questions Roadmap: Ansible

More on Roles, Collections and Galaxy