Skip to content

fix: jinja2 contextfilter -> pass_context #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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