Deprecation of ANSIBLE_JINJA2_EXTENSIONS - what to 'do'?

I am running a sizable deployment of ansible with a bit of tooling around it to make things work for me.

Some templates for example for network and network services gather extensive amount of data from the environment, process it and generate configuration using jinja2 and templates. I use the jinja2 ‘do’ extension via ANSIBLE_JINJA2_EXTENSIONS to overcome jinja2s scoping specifics and carry data out of loops etc.

ansible-core seems to have deprecated adding jinja2 extensions without addressing how to migrate current usecases to different solutions.

any ideas how to deal with jinja loop contexts and carrying data out of them without using the ‘do’ extension?

I never used it, but from its description it sounds very similar to {% set _ = <expression> %} (Template Designer Documentation — Jinja Documentation (3.1.x)). Maybe that can be used instead (without any extension)?

Thanks for referring me back to the documentation about the scoping behavior :).

set alone doesn’t seem to solve it (it doesn’t carry the data out of the loop) but i will try to use the namespace feature that is documented there and available since jinja 2.10. I didn’t even know about that. <3

Thanks, Felix

I totally misuderstood what you meant, sorry. Sure, assigning the result (usually None of the append call to _ should do the trick as well … sorry for the confusion and thanks again.

1 Like

No worries, I’m glad you figured it out :slight_smile:

1 Like