|
|
@ -455,6 +455,7 @@ class JinjaPluginIntercept(MutableMapping):
|
|
|
|
# FUTURE: we can cache FQ filter/test calls for the entire duration of a run, since a given collection's impl's
|
|
|
|
# FUTURE: we can cache FQ filter/test calls for the entire duration of a run, since a given collection's impl's
|
|
|
|
# aren't supposed to change during a run
|
|
|
|
# aren't supposed to change during a run
|
|
|
|
def __getitem__(self, key):
|
|
|
|
def __getitem__(self, key):
|
|
|
|
|
|
|
|
original_key = key
|
|
|
|
self._load_ansible_plugins()
|
|
|
|
self._load_ansible_plugins()
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
@ -469,11 +470,16 @@ class JinjaPluginIntercept(MutableMapping):
|
|
|
|
if func:
|
|
|
|
if func:
|
|
|
|
return func
|
|
|
|
return func
|
|
|
|
|
|
|
|
|
|
|
|
# didn't find it in the pre-built Jinja env, assume it's a former builtin and follow the normal routing path
|
|
|
|
key, leaf_key = get_fqcr_and_name(key)
|
|
|
|
leaf_key = key
|
|
|
|
seen = set()
|
|
|
|
key = 'ansible.builtin.' + key
|
|
|
|
|
|
|
|
else:
|
|
|
|
while True:
|
|
|
|
leaf_key = key.split('.')[-1]
|
|
|
|
if key in seen:
|
|
|
|
|
|
|
|
raise TemplateSyntaxError(
|
|
|
|
|
|
|
|
'recursive collection redirect found for %r' % original_key,
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
seen.add(key)
|
|
|
|
|
|
|
|
|
|
|
|
acr = AnsibleCollectionRef.try_parse_fqcr(key, self._dirname)
|
|
|
|
acr = AnsibleCollectionRef.try_parse_fqcr(key, self._dirname)
|
|
|
|
|
|
|
|
|
|
|
@ -482,7 +488,6 @@ class JinjaPluginIntercept(MutableMapping):
|
|
|
|
|
|
|
|
|
|
|
|
ts = _get_collection_metadata(acr.collection)
|
|
|
|
ts = _get_collection_metadata(acr.collection)
|
|
|
|
|
|
|
|
|
|
|
|
# TODO: implement support for collection-backed redirect (currently only builtin)
|
|
|
|
|
|
|
|
# TODO: implement cycle detection (unified across collection redir as well)
|
|
|
|
# TODO: implement cycle detection (unified across collection redir as well)
|
|
|
|
|
|
|
|
|
|
|
|
routing_entry = ts.get('plugin_routing', {}).get(self._dirname, {}).get(leaf_key, {})
|
|
|
|
routing_entry = ts.get('plugin_routing', {}).get(self._dirname, {}).get(leaf_key, {})
|
|
|
@ -513,12 +518,13 @@ class JinjaPluginIntercept(MutableMapping):
|
|
|
|
|
|
|
|
|
|
|
|
raise AnsiblePluginRemovedError(exc_msg)
|
|
|
|
raise AnsiblePluginRemovedError(exc_msg)
|
|
|
|
|
|
|
|
|
|
|
|
redirect_fqcr = routing_entry.get('redirect', None)
|
|
|
|
redirect = routing_entry.get('redirect', None)
|
|
|
|
if redirect_fqcr:
|
|
|
|
if redirect:
|
|
|
|
acr = AnsibleCollectionRef.from_fqcr(ref=redirect_fqcr, ref_type=self._dirname)
|
|
|
|
next_key, leaf_key = get_fqcr_and_name(redirect, collection=acr.collection)
|
|
|
|
display.vvv('redirecting {0} {1} to {2}.{3}'.format(self._dirname, key, acr.collection, acr.resource))
|
|
|
|
display.vvv('redirecting (type: {0}) {1}.{2} to {3}'.format(self._dirname, acr.collection, acr.resource, next_key))
|
|
|
|
key = redirect_fqcr
|
|
|
|
key = next_key
|
|
|
|
# TODO: handle recursive forwarding (not necessary for builtin, but definitely for further collection redirs)
|
|
|
|
else:
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
func = self._collection_jinja_func_cache.get(key)
|
|
|
|
func = self._collection_jinja_func_cache.get(key)
|
|
|
|
|
|
|
|
|
|
|
@ -593,6 +599,17 @@ class JinjaPluginIntercept(MutableMapping):
|
|
|
|
return len(self._delegatee)
|
|
|
|
return len(self._delegatee)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_fqcr_and_name(resource, collection='ansible.builtin'):
|
|
|
|
|
|
|
|
if '.' not in resource:
|
|
|
|
|
|
|
|
name = resource
|
|
|
|
|
|
|
|
fqcr = collection + '.' + resource
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
name = resource.split('.')[-1]
|
|
|
|
|
|
|
|
fqcr = resource
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return fqcr, name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@_unroll_iterator
|
|
|
|
@_unroll_iterator
|
|
|
|
def _ansible_finalize(thing):
|
|
|
|
def _ansible_finalize(thing):
|
|
|
|
"""A custom finalize function for jinja2, which prevents None from being
|
|
|
|
"""A custom finalize function for jinja2, which prevents None from being
|
|
|
|