mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-12 08:00:51 -07:00
[stable-9] Make ready for data tagging (#9991)
Make ready for data tagging (#9833)
* Fix dependent lookup.
* Fix ansible_type plugin utils and adjust documentation of reveal_ansible_type filter and ansible_type test.
* Fix diy callback plugin.
* Adjust to Data Tagging.
* Vendor and use internal code from ansible-core to fix YAML callback.
Ref: https://github.com/ansible/ansible/issues/84781
(cherry picked from commit 04cfce78ea
)
This commit is contained in:
parent
ff7a8f8018
commit
f12f69d2a5
13 changed files with 372 additions and 165 deletions
|
@ -130,12 +130,24 @@ from ansible.template import Templar
|
|||
|
||||
from ansible_collections.community.general.plugins.module_utils.version import LooseVersion
|
||||
|
||||
try:
|
||||
from ansible.template import trust_as_template as _trust_as_template
|
||||
HAS_DATATAGGING = True
|
||||
except ImportError:
|
||||
HAS_DATATAGGING = False
|
||||
|
||||
|
||||
# Whether Templar has a cache, which can be controlled by Templar.template()'s cache option.
|
||||
# The cache was removed for ansible-core 2.14 (https://github.com/ansible/ansible/pull/78419)
|
||||
_TEMPLAR_HAS_TEMPLATE_CACHE = LooseVersion(ansible_version) < LooseVersion('2.14.0')
|
||||
|
||||
|
||||
def _make_safe(value):
|
||||
if HAS_DATATAGGING and isinstance(value, str):
|
||||
return _trust_as_template(value)
|
||||
return value
|
||||
|
||||
|
||||
class LookupModule(LookupBase):
|
||||
def __evaluate(self, expression, templar, variables):
|
||||
"""Evaluate expression with templar.
|
||||
|
@ -144,10 +156,13 @@ class LookupModule(LookupBase):
|
|||
``variables`` are the variables to use.
|
||||
"""
|
||||
templar.available_variables = variables or {}
|
||||
expression = "{0}{1}{2}".format("{{", expression, "}}")
|
||||
quoted_expression = "{0}{1}{2}".format("{{", expression, "}}")
|
||||
if _TEMPLAR_HAS_TEMPLATE_CACHE:
|
||||
return templar.template(expression, cache=False)
|
||||
return templar.template(expression)
|
||||
return templar.template(quoted_expression, cache=False)
|
||||
if hasattr(templar, 'evaluate_expression'):
|
||||
# This is available since the Data Tagging PR has been merged
|
||||
return templar.evaluate_expression(_make_safe(expression))
|
||||
return templar.template(quoted_expression)
|
||||
|
||||
def __process(self, result, terms, index, current, templar, variables):
|
||||
"""Fills ``result`` list with evaluated items.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue