Skip to content

Commit f206267

Browse files
authored
Merge pull request #35 from stackhpc/contextfilter_fix
2 parents 467fc36 + 473691f commit f206267

File tree

1 file changed

+7
-2
lines changed
  • ansible/roles/config-diff-vars/filter_plugins

1 file changed

+7
-2
lines changed

ansible/roles/config-diff-vars/filter_plugins/utils.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import jinja2
22
from ansible import errors
3+
# NOTE: jinja2 3.1.0 dropped contextfilter in favour of pass_context.
4+
try:
5+
from jinja2 import pass_context
6+
except ImportError:
7+
from jinja2 import contextfilter as pass_context
38

49

510
def _get_hostvar(context, var_name, inventory_hostname=None):
@@ -56,7 +61,7 @@ def dummy_facts_prefix(facts, inject_facts):
5661
def interface_string(interface):
5762
return "\"{{ lookup('vars', inventory_hostname | replace('-', '_') ~ '_' ~ '" + interface + "') }}\""
5863

59-
@jinja2.contextfilter
64+
@pass_context
6065
def ip_mappings(context, hosts):
6166
hosts = set(hosts)
6267
result = {}
@@ -74,7 +79,7 @@ def ip_mappings(context, hosts):
7479
})
7580
return result
7681

77-
@jinja2.contextfilter
82+
@pass_context
7883
def dummy_facts_interfaces(context, host):
7984
result = {}
8085
mappings = ip_mappings(context, [host]).get(host, [])

0 commit comments

Comments
 (0)