Skip to content

Commit

Permalink
Merge pull request #35 from stackhpc/contextfilter_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jackhodgkiss committed Sep 12, 2023
2 parents 467fc36 + 473691f commit f206267
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions ansible/roles/config-diff-vars/filter_plugins/utils.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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 = {}
Expand All @@ -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, [])
Expand Down

0 comments on commit f206267

Please sign in to comment.