-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add docs for the filter reveal_ansible_type and the test ansible_type. #8645
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,144 @@ | ||||||||
.. | ||||||||
Copyright (c) Ansible Project | ||||||||
GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) | ||||||||
SPDX-License-Identifier: GPL-3.0-or-later | ||||||||
|
||||||||
Filter reveal_ansible_type | ||||||||
"""""""""""""""""""""""""" | ||||||||
|
||||||||
Use the filter :ansplugin:`community.general.reveal_ansible_type#filter` if you want to get the type of Ansible data. | ||||||||
|
||||||||
.. note:: The output of the examples in this section use the YAML callback plugin. Quoting: "Ansible output that can be quite a bit easier to read than the default JSON formatting." See :ansplugin:`the documentation for the community.general.yaml callback plugin <community.general.yaml#callback>`. | ||||||||
|
||||||||
.. versionadded:: 9.2.0 | ||||||||
|
||||||||
**Substitution converts str to AnsibleUnicode** | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a heading, so it should be a heading and not a paragraph with manual formatting applied:
Suggested change
Similar below. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would violate the heading levels:
I'm afraid there are no more levels left. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. RST allows quite a few different levels. You can use |
||||||||
|
||||||||
* String. AnsibleUnicode. | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this mean? (I know what it means, but regular users do not.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll improve all the comments. |
||||||||
|
||||||||
.. code-block:: yaml+jinja | ||||||||
|
||||||||
data: "abc" | ||||||||
result: '{{ data | community.general.reveal_ansible_type }}' | ||||||||
# result => AnsibleUnicode | ||||||||
|
||||||||
* String. AnsibleUnicode alias str. | ||||||||
|
||||||||
.. code-block:: yaml+jinja | ||||||||
|
||||||||
alias: {"AnsibleUnicode": "str"} | ||||||||
data: "abc" | ||||||||
result: '{{ data | community.general.reveal_ansible_type(alias) }}' | ||||||||
# result => str | ||||||||
|
||||||||
* List. All items are AnsibleUnicode. | ||||||||
|
||||||||
.. code-block:: yaml+jinja | ||||||||
|
||||||||
data: ["a", "b", "c"] | ||||||||
result: '{{ data | community.general.reveal_ansible_type }}' | ||||||||
# result => list[AnsibleUnicode] | ||||||||
|
||||||||
* Dictionary. All keys are AnsibleUnicode. All values are AnsibleUnicode. | ||||||||
|
||||||||
.. code-block:: yaml+jinja | ||||||||
|
||||||||
data: {"a": "foo", "b": "bar", "c": "baz"} | ||||||||
result: '{{ data | community.general.reveal_ansible_type }}' | ||||||||
# result => dict[AnsibleUnicode, AnsibleUnicode] | ||||||||
|
||||||||
**No substitution and no alias. Type of strings is str** | ||||||||
|
||||||||
* String | ||||||||
|
||||||||
.. code-block:: yaml+jinja | ||||||||
|
||||||||
result: '{{ "abc" | community.general.reveal_ansible_type }}' | ||||||||
# result => str | ||||||||
|
||||||||
* Integer | ||||||||
|
||||||||
.. code-block:: yaml+jinja | ||||||||
|
||||||||
result: '{{ 123 | community.general.reveal_ansible_type }}' | ||||||||
# result => int | ||||||||
|
||||||||
* Float | ||||||||
|
||||||||
.. code-block:: yaml+jinja | ||||||||
|
||||||||
result: '{{ 123.45 | community.general.reveal_ansible_type }}' | ||||||||
# result => float | ||||||||
|
||||||||
* Boolean | ||||||||
|
||||||||
.. code-block:: yaml+jinja | ||||||||
|
||||||||
result: '{{ true | community.general.reveal_ansible_type }}' | ||||||||
# result => bool | ||||||||
|
||||||||
* List. All items are strings. | ||||||||
|
||||||||
.. code-block:: yaml+jinja | ||||||||
|
||||||||
result: '{{ ["a", "b", "c"] | community.general.reveal_ansible_type }}' | ||||||||
# result => list[str] | ||||||||
|
||||||||
* List of dictionaries. | ||||||||
|
||||||||
.. code-block:: yaml+jinja | ||||||||
|
||||||||
result: '{{ [{"a": 1}, {"b": 2}] | community.general.reveal_ansible_type }}' | ||||||||
# result => list[dict] | ||||||||
|
||||||||
* Dictionary. All keys are strings. All values are integers. | ||||||||
|
||||||||
.. code-block:: yaml+jinja | ||||||||
|
||||||||
result: '{{ {"a": 1} | community.general.reveal_ansible_type }}' | ||||||||
# result => dict[str, int] | ||||||||
|
||||||||
* Dictionary. All keys are strings. All values are integers. | ||||||||
|
||||||||
.. code-block:: yaml+jinja | ||||||||
|
||||||||
result: '{{ {"a": 1, "b": 2} | community.general.reveal_ansible_type }}' | ||||||||
# result => dict[str, int] | ||||||||
|
||||||||
**Type of strings is AnsibleUnicode or str** | ||||||||
|
||||||||
* Dictionary. The keys are integers or strings. All values are strings. | ||||||||
|
||||||||
.. code-block:: yaml+jinja | ||||||||
|
||||||||
alias: {"AnsibleUnicode": "str"} | ||||||||
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. | ||||||||
|
||||||||
.. code-block:: yaml+jinja | ||||||||
|
||||||||
alias: {"AnsibleUnicode": "str"} | ||||||||
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. | ||||||||
|
||||||||
.. code-block:: yaml+jinja | ||||||||
|
||||||||
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) }}' | ||||||||
# result => dict[str, bool|dict|float|int|list|str] | ||||||||
|
||||||||
* List. Multiple types items. | ||||||||
|
||||||||
.. code-block:: yaml+jinja | ||||||||
|
||||||||
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) }}' | ||||||||
# result => list[bool|dict|float|int|list|str] |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,14 @@ | ||||||
.. | ||||||
Copyright (c) Ansible Project | ||||||
GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) | ||||||
SPDX-License-Identifier: GPL-3.0-or-later | ||||||
|
||||||
Types | ||||||
^^^^^ | ||||||
|
||||||
Filters to manage Ansible types | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
.. toctree:: | ||||||
:maxdepth: 1 | ||||||
|
||||||
filter_guide-abstract_informations-types-reveal_ansible_type |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This removes existing documentation for existing plugins. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I restored the origin and added new section. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use underscores:
Same below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed?
The name of the file is a concatenation of three headings' levels:
The concatenation by dash "-" keeps this information. I've already created a couple of files this way. Should all of them be renamed?
You kept the first dash. Do you think this one should be replaced too?
For the record: This name is used in filter_guide_abstract_informations.rst
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't catch the dashes in the previous PR. Generally all filenames in docs/docsite/rst/ use underscores instead of dashes. It would be great to keep it that way.