Skip to content

ansible deprecation warning about DEFAULT_JINJA2_EXTENSIONS related to "jinja2_extensions = jinja2.ext.loopcontrols" line

We are getting this deprecation warning from ansible on Debian trixie:

root@nisse-01:~# ansible --version
[WARNING]: Deprecation warnings can be disabled by setting `deprecation_warnings=False` in ansible.cfg.
[DEPRECATION WARNING]: DEFAULT_JINJA2_EXTENSIONS option. Reason: Jinja2 extensions have been deprecated
Alternatives: Ansible-supported Jinja plugins (tests, filters, lookups). This feature will be removed from ansible-core version 2.23.

ansible [core 2.19.0b6]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.13.5 (main, Jun 25 2025, 18:55:22) [GCC 14.2.0] (/usr/bin/python3)
  jinja version = 3.1.6
  pyyaml version = 6.0.2 (with libyaml v0.2.5)

The warning disappears if the following line in /etc/ansible/ansible.cfg is removed:

jinja2_extensions = jinja2.ext.loopcontrols

That loopcontrols extension is described as follows: "This extension "adds support for break and continue in loops. After enabling, Jinja provides those two keywords which work exactly like in Python."

One place where we use jinja2 "continue" is in roles/apache2/templates/virtual_host.conf.j2 in the site ansible repo.

Perhaps we should rewrite that template and any others to not use break and continue in jinja2 loops, and then we could remove the jinja2_extensions = jinja2.ext.loopcontrols line?