summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMatt Clay <mclay@redhat.com>2021-05-12 12:50:12 -0700
committerGitHub <noreply@github.com>2021-05-12 12:50:12 -0700
commitc3108305537447200873342b9a5f6f6377b0a9fd (patch)
tree1a6dc5ca527b74460837a7024a92f835a2a2132d /lib
parentd8d20a2ff95547e11841e3fdd4f2d9caee9ade6c (diff)
downloadansible-c3108305537447200873342b9a5f6f6377b0a9fd.tar.gz
[stable-2.9] CI and compat fixes for Jinja2 >= 3.0 (#74666) (#74672)
* [stable-2.9] CI and compat fixes for Jinja2 >= 3.0 (#74666) * Add constraint for MarkupSafe MarkupSafe >= 2.0.0 requires Python >= 3.6.0. Add a constraint for older Python versions and fix the `groupby_filter` test. * Fix template_jinja2_latest test. * patch filter decorators on newer Jinja2 * Jinja2 >= 3.0 renames several filter decorators used by Ansible itself, as well as by filters in collections. This patch ensures that the old names are usable within Ansible and by collections without warnings or errors. * Ignore docs-build issues. * Remove unnecessary ignore. * Disable failing nuage_vspk test. * Fix inventory_aws_conformance integration test. (cherry picked from commit f99d0248517c9dacc4594bc87d54626cdce59bfd) Co-authored-by: Matt Clay <matt@mystile.com> Co-authored-by: Matt Davis <mrd@redhat.com>. Co-authored-by: Sam Doran <sdoran@redhat.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/ansible/__init__.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/ansible/__init__.py b/lib/ansible/__init__.py
index d8aeac5e58..19844dd920 100644
--- a/lib/ansible/__init__.py
+++ b/lib/ansible/__init__.py
@@ -19,6 +19,17 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
+# patch Jinja2 >= 3.0 for backwards compatibility
+try:
+ import sys as _sys
+ from jinja2.filters import pass_context as _passctx, pass_environment as _passenv, pass_eval_context as _passevalctx
+ _mod = _sys.modules['jinja2.filters']
+ _mod.contextfilter = _passctx
+ _mod.environmentfilter = _passenv
+ _mod.evalcontextfilter = _passevalctx
+except ImportError:
+ _sys = None
+
# Note: Do not add any code to this file. The ansible module may be
# a namespace package when using Ansible-2.1+ Anything in this file may not be
# available if one of the other packages in the namespace is loaded first.