Jinja macros as plugins

utoddl
Fri, 13 Oct 2023 20:49:27 +0000
Project Discussions

Continuing the discussion from Playbook-wide Jinja2 macros over in Get Help :

TL;DR — The idea is to allow macros defined in a collection’s plugins/macros directory to be available in Jinja expressions without requiring additional syntax in much the same way that custom lookups and filters are made available now.

@nitzmahone from the core team provided interesting technical background with implications for implementation, particularly that it would be much cleaner if such a feature were restricted to collections. I (@utoddl) provided a use case, and @gwmngilfen suggested this discussion could be a better fit here in Project Discussions than in Get Help, so here it is!

Since macros are built-in to Jinja, it should be possible to implement all-Jinja solutions to problems that would otherwise require implementing custom filters in Python, and that may be one step farther than some Ansible users are ready to take.

I’d be particularly interested in hearing use cases and thoughts from others.

1 post - 1 participant