From 473691feb40c494a2d807d6c5ea00a594ee07467 Mon Sep 17 00:00:00 2001 From: Jack Hodgkiss Date: Mon, 11 Sep 2023 15:10:20 +0100 Subject: [PATCH] fix: jinja2 contextfilter -> pass_context --- ansible/roles/config-diff-vars/filter_plugins/utils.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ansible/roles/config-diff-vars/filter_plugins/utils.py b/ansible/roles/config-diff-vars/filter_plugins/utils.py index cff20f8..bf2c4a7 100644 --- a/ansible/roles/config-diff-vars/filter_plugins/utils.py +++ b/ansible/roles/config-diff-vars/filter_plugins/utils.py @@ -1,5 +1,10 @@ import jinja2 from ansible import errors +# NOTE: jinja2 3.1.0 dropped contextfilter in favour of pass_context. +try: + from jinja2 import pass_context +except ImportError: + from jinja2 import contextfilter as pass_context def _get_hostvar(context, var_name, inventory_hostname=None): @@ -56,7 +61,7 @@ def dummy_facts_prefix(facts, inject_facts): def interface_string(interface): return "\"{{ lookup('vars', inventory_hostname | replace('-', '_') ~ '_' ~ '" + interface + "') }}\"" -@jinja2.contextfilter +@pass_context def ip_mappings(context, hosts): hosts = set(hosts) result = {} @@ -74,7 +79,7 @@ def ip_mappings(context, hosts): }) return result -@jinja2.contextfilter +@pass_context def dummy_facts_interfaces(context, host): result = {} mappings = ip_mappings(context, [host]).get(host, [])