mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 04:40:22 -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
|
@ -23,93 +23,107 @@ DOCUMENTATION = '''
|
|||
type: dictionary
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
# Substitution converts str to AnsibleUnicode
|
||||
# -------------------------------------------
|
||||
EXAMPLES = r"""
|
||||
# Substitution converts str to AnsibleUnicode or _AnsibleTaggedStr
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
# String. AnsibleUnicode.
|
||||
data: "abc"
|
||||
result: '{{ data | community.general.reveal_ansible_type }}'
|
||||
# result => AnsibleUnicode
|
||||
# String. AnsibleUnicode or _AnsibleTaggedStr.
|
||||
- data: "abc"
|
||||
result: '{{ data | community.general.reveal_ansible_type }}'
|
||||
# result => AnsibleUnicode (or _AnsibleTaggedStr)
|
||||
|
||||
# String. AnsibleUnicode alias str.
|
||||
alias: {"AnsibleUnicode": "str"}
|
||||
data: "abc"
|
||||
result: '{{ data | community.general.reveal_ansible_type(alias) }}'
|
||||
# String. AnsibleUnicode/_AnsibleTaggedStr alias str.
|
||||
- alias: {"AnsibleUnicode": "str", "_AnsibleTaggedStr": "str"}
|
||||
data: "abc"
|
||||
result: '{{ data | community.general.reveal_ansible_type(alias) }}'
|
||||
# result => str
|
||||
|
||||
# List. All items are AnsibleUnicode.
|
||||
data: ["a", "b", "c"]
|
||||
result: '{{ data | community.general.reveal_ansible_type }}'
|
||||
# result => list[AnsibleUnicode]
|
||||
# List. All items are AnsibleUnicode/_AnsibleTaggedStr.
|
||||
- data: ["a", "b", "c"]
|
||||
result: '{{ data | community.general.reveal_ansible_type }}'
|
||||
# result => list[AnsibleUnicode] or list[_AnsibleTaggedStr]
|
||||
|
||||
# Dictionary. All keys are AnsibleUnicode. All values are AnsibleUnicode.
|
||||
data: {"a": "foo", "b": "bar", "c": "baz"}
|
||||
result: '{{ data | community.general.reveal_ansible_type }}'
|
||||
# result => dict[AnsibleUnicode, AnsibleUnicode]
|
||||
# Dictionary. All keys and values are AnsibleUnicode/_AnsibleTaggedStr.
|
||||
- data: {"a": "foo", "b": "bar", "c": "baz"}
|
||||
result: '{{ data | community.general.reveal_ansible_type }}'
|
||||
# result => dict[AnsibleUnicode, AnsibleUnicode] or dict[_AnsibleTaggedStr, _AnsibleTaggedStr]
|
||||
|
||||
# No substitution and no alias. Type of strings is str
|
||||
# ----------------------------------------------------
|
||||
|
||||
# String
|
||||
result: '{{ "abc" | community.general.reveal_ansible_type }}'
|
||||
- result: '{{ "abc" | community.general.reveal_ansible_type }}'
|
||||
# result => str
|
||||
|
||||
# Integer
|
||||
result: '{{ 123 | community.general.reveal_ansible_type }}'
|
||||
- result: '{{ 123 | community.general.reveal_ansible_type }}'
|
||||
# result => int
|
||||
|
||||
# Float
|
||||
result: '{{ 123.45 | community.general.reveal_ansible_type }}'
|
||||
- result: '{{ 123.45 | community.general.reveal_ansible_type }}'
|
||||
# result => float
|
||||
|
||||
# Boolean
|
||||
result: '{{ true | community.general.reveal_ansible_type }}'
|
||||
- result: '{{ true | community.general.reveal_ansible_type }}'
|
||||
# result => bool
|
||||
|
||||
# List. All items are strings.
|
||||
result: '{{ ["a", "b", "c"] | community.general.reveal_ansible_type }}'
|
||||
- result: '{{ ["a", "b", "c"] | community.general.reveal_ansible_type }}'
|
||||
# result => list[str]
|
||||
|
||||
# List of dictionaries.
|
||||
result: '{{ [{"a": 1}, {"b": 2}] | community.general.reveal_ansible_type }}'
|
||||
- result: '{{ [{"a": 1}, {"b": 2}] | community.general.reveal_ansible_type }}'
|
||||
# result => list[dict]
|
||||
|
||||
# Dictionary. All keys are strings. All values are integers.
|
||||
result: '{{ {"a": 1} | community.general.reveal_ansible_type }}'
|
||||
- result: '{{ {"a": 1} | community.general.reveal_ansible_type }}'
|
||||
# result => dict[str, int]
|
||||
|
||||
# Dictionary. All keys are strings. All values are integers.
|
||||
result: '{{ {"a": 1, "b": 2} | community.general.reveal_ansible_type }}'
|
||||
- result: '{{ {"a": 1, "b": 2} | community.general.reveal_ansible_type }}'
|
||||
# result => dict[str, int]
|
||||
|
||||
# Type of strings is AnsibleUnicode or str
|
||||
# ----------------------------------------
|
||||
# Type of strings is AnsibleUnicode, _AnsibleTaggedStr, or str
|
||||
# ------------------------------------------------------------
|
||||
|
||||
# Dictionary. The keys are integers or strings. All values are strings.
|
||||
alias: {"AnsibleUnicode": "str"}
|
||||
data: {1: 'a', 'b': 'b'}
|
||||
result: '{{ data | community.general.reveal_ansible_type(alias) }}'
|
||||
- alias:
|
||||
AnsibleUnicode: str
|
||||
_AnsibleTaggedStr: str
|
||||
_AnsibleTaggedInt: int
|
||||
data: {1: 'a', 'b': 'b'}
|
||||
result: '{{ data | community.general.reveal_ansible_type(alias) }}'
|
||||
# result => dict[int|str, str]
|
||||
|
||||
# Dictionary. All keys are integers. All values are keys.
|
||||
alias: {"AnsibleUnicode": "str"}
|
||||
data: {1: 'a', 2: 'b'}
|
||||
result: '{{ data | community.general.reveal_ansible_type(alias) }}'
|
||||
- alias:
|
||||
AnsibleUnicode: str
|
||||
_AnsibleTaggedStr: str
|
||||
_AnsibleTaggedInt: int
|
||||
data: {1: 'a', 2: 'b'}
|
||||
result: '{{ data | community.general.reveal_ansible_type(alias) }}'
|
||||
# result => dict[int, str]
|
||||
|
||||
# Dictionary. All keys are strings. Multiple types values.
|
||||
alias: {"AnsibleUnicode": "str"}
|
||||
data: {'a': 1, 'b': 1.1, 'c': 'abc', 'd': True, 'e': ['x', 'y', 'z'], 'f': {'x': 1, 'y': 2}}
|
||||
result: '{{ data | community.general.reveal_ansible_type(alias) }}'
|
||||
- alias:
|
||||
AnsibleUnicode: str
|
||||
_AnsibleTaggedStr: str
|
||||
_AnsibleTaggedInt: int
|
||||
_AnsibleTaggedFloat: float
|
||||
data: {'a': 1, 'b': 1.1, 'c': 'abc', 'd': true, 'e': ['x', 'y', 'z'], 'f': {'x': 1, 'y': 2}}
|
||||
result: '{{ data | community.general.reveal_ansible_type(alias) }}'
|
||||
# result => dict[str, bool|dict|float|int|list|str]
|
||||
|
||||
# List. Multiple types items.
|
||||
alias: {"AnsibleUnicode": "str"}
|
||||
data: [1, 2, 1.1, 'abc', True, ['x', 'y', 'z'], {'x': 1, 'y': 2}]
|
||||
result: '{{ data | community.general.reveal_ansible_type(alias) }}'
|
||||
- alias:
|
||||
AnsibleUnicode: str
|
||||
_AnsibleTaggedStr: str
|
||||
_AnsibleTaggedInt: int
|
||||
_AnsibleTaggedFloat: float
|
||||
data: [1, 2, 1.1, 'abc', true, ['x', 'y', 'z'], {'x': 1, 'y': 2}]
|
||||
result: '{{ data | community.general.reveal_ansible_type(alias) }}'
|
||||
# result => list[bool|dict|float|int|list|str]
|
||||
'''
|
||||
"""
|
||||
|
||||
RETURN = '''
|
||||
_value:
|
||||
|
@ -123,6 +137,7 @@ from ansible_collections.community.general.plugins.plugin_utils.ansible_type imp
|
|||
def reveal_ansible_type(data, alias=None):
|
||||
"""Returns data type"""
|
||||
|
||||
# TODO: expose use_native_type parameter
|
||||
return _ansible_type(data, alias)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue