From 5f70e6e241df44def81c48cbb3a142a719756288 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Wed, 16 Jul 2025 20:45:58 +0200 Subject: [PATCH 1/6] Add result_format_callback docs fragment. --- changelogs/fragments/10422-tasks_only-result_format.yml | 2 ++ plugins/callback/tasks_only.py | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/10422-tasks_only-result_format.yml diff --git a/changelogs/fragments/10422-tasks_only-result_format.yml b/changelogs/fragments/10422-tasks_only-result_format.yml new file mode 100644 index 0000000000..13e5e749bf --- /dev/null +++ b/changelogs/fragments/10422-tasks_only-result_format.yml @@ -0,0 +1,2 @@ +minor_changes: + - "tasks_only callback plugin - add ``result_format`` and ``pretty_results`` options similarly to the default callback (https://github.com/ansible-collections/community.general/pull/10422)." diff --git a/plugins/callback/tasks_only.py b/plugins/callback/tasks_only.py index f64c4c57db..243ec9661d 100644 --- a/plugins/callback/tasks_only.py +++ b/plugins/callback/tasks_only.py @@ -17,7 +17,8 @@ description: - Can be used to generate output for documentation examples. For this, the O(number_of_columns) option should be set to an explicit value. extends_documentation_fragment: - - default_callback + - ansible.builtin.default_callback + - ansible.builtin.result_format_callback options: number_of_columns: description: @@ -25,6 +26,12 @@ options: type: int env: - name: ANSIBLE_COLLECTIONS_TASKS_ONLY_NUMBER_OF_COLUMNS + result_format: + # Part of the ansible.builtin.result_format_callback doc fragment + version_added: 11.2.0 + pretty_results: + # Part of the ansible.builtin.result_format_callback doc fragment + version_added: 11.2.0 """ EXAMPLES = r""" From e194a38061845181b6bb2687fe09d69f2fa63ef1 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Wed, 16 Jul 2025 15:28:10 +0200 Subject: [PATCH 2/6] Generate many Ansible outputs with 'antsibull-docs ansible-output'. --- docs/docsite/config.yml | 5 +++ ...rmations_counting_elements_in_sequence.rst | 24 +++++++++- ...ide_abstract_informations_dictionaries.rst | 32 ++++++++++--- ...r_guide_abstract_informations_grouping.rst | 45 ++++++++++++++++++- docs/docsite/rst/filter_guide_conversions.rst | 39 ++++++++++++++++ .../rst/filter_guide_creating_identifiers.rst | 31 ++++++++++++- .../rst/filter_guide_working_with_times.rst | 17 +++++-- .../rst/filter_guide_working_with_unicode.rst | 13 +++++- .../filter_guide_working_with_versions.rst | 11 +++++ noxfile.py | 12 +++++ 10 files changed, 216 insertions(+), 13 deletions(-) diff --git a/docs/docsite/config.yml b/docs/docsite/config.yml index 1d6cf8554a..50b4a2f347 100644 --- a/docs/docsite/config.yml +++ b/docs/docsite/config.yml @@ -5,3 +5,8 @@ changelog: write_changelog: true + +ansible_output: + global_env: + ANSIBLE_STDOUT_CALLBACK: community.general.tasks_only + ANSIBLE_COLLECTIONS_TASKS_ONLY_NUMBER_OF_COLUMNS: 90 diff --git a/docs/docsite/rst/filter_guide_abstract_informations_counting_elements_in_sequence.rst b/docs/docsite/rst/filter_guide_abstract_informations_counting_elements_in_sequence.rst index 98e8eb1c4d..84759701f5 100644 --- a/docs/docsite/rst/filter_guide_abstract_informations_counting_elements_in_sequence.rst +++ b/docs/docsite/rst/filter_guide_abstract_informations_counting_elements_in_sequence.rst @@ -20,6 +20,17 @@ The :ansplugin:`community.general.counter filter plugin { "msg": "scsi_2" } diff --git a/docs/docsite/rst/filter_guide_abstract_informations_dictionaries.rst b/docs/docsite/rst/filter_guide_abstract_informations_dictionaries.rst index e5b5bb7e36..dcc4a96369 100644 --- a/docs/docsite/rst/filter_guide_abstract_informations_dictionaries.rst +++ b/docs/docsite/rst/filter_guide_abstract_informations_dictionaries.rst @@ -31,16 +31,27 @@ You can use the :ansplugin:`community.general.dict_kv filter { "msg": { "thatsmyvar": "myvalue" } } - TASK [Create a list of dictionaries where the 'server' field is taken from a list] ******* + TASK [Create a list of dictionaries where the 'server' field is taken from a list] ******** ok: [localhost] => { "msg": [ { @@ -87,9 +98,20 @@ If you need to convert a list of key-value pairs to a dictionary, you can use th This produces: +.. ansible-output-data:: + + variables: + task: + previous_code_block: yaml+jinja + playbook: |- + - hosts: localhost + gather_facts: false + tasks: + @{{ task | indent(4) }}@ + .. code-block:: ansible-output - TASK [Create a dictionary with the dict function] **************************************** + TASK [Create a dictionary with the dict function] ***************************************** ok: [localhost] => { "msg": { "1": 2, @@ -97,7 +119,7 @@ This produces: } } - TASK [Create a dictionary with the community.general.dict filter] ************************ + TASK [Create a dictionary with the community.general.dict filter] ************************* ok: [localhost] => { "msg": { "1": 2, @@ -105,7 +127,7 @@ This produces: } } - TASK [Create a list of dictionaries with map and the community.general.dict filter] ****** + TASK [Create a list of dictionaries with map and the community.general.dict filter] ******* ok: [localhost] => { "msg": [ { diff --git a/docs/docsite/rst/filter_guide_abstract_informations_grouping.rst b/docs/docsite/rst/filter_guide_abstract_informations_grouping.rst index cb15989659..f73f2256fe 100644 --- a/docs/docsite/rst/filter_guide_abstract_informations_grouping.rst +++ b/docs/docsite/rst/filter_guide_abstract_informations_grouping.rst @@ -22,6 +22,49 @@ One example is ``ansible_facts.mounts``, which is a list of dictionaries where e This produces: +.. ansible-output-data:: + + variables: + task: + previous_code_block: yaml+jinja + skip_first_lines: 3 # the set_fact task + playbook: |- + - hosts: localhost + gather_facts: false + tasks: + - ansible.builtin.set_fact: + ansible_facts: + mounts: + - block_available: 2000 + block_size: 4096 + block_total: 2345 + block_used: 345 + device: "/dev/sda1" + fstype: "ext4" + inode_available: 500 + inode_total: 512 + inode_used: 12 + mount: "/boot" + options: "rw,relatime,data=ordered" + size_available: 56821 + size_total: 543210 + uuid: "ab31cade-d9c1-484d-8482-8a4cbee5241a" + - block_available: 1234 + block_size: 4096 + block_total: 12345 + block_used: 11111 + device: "/dev/sda2" + fstype: "ext4" + inode_available: 1111 + inode_total: 1234 + inode_used: 123 + mount: "/" + options: "rw,relatime" + size_available: 42143 + size_total: 543210 + uuid: "abcdef01-2345-6789-0abc-def012345678" + @{{ task | indent(4) }}@ + .. code-block:: ansible-output TASK [Output mount facts grouped by device name] ****************************************** @@ -79,7 +122,7 @@ This produces: "options": "rw,relatime", "size_available": 42143, "size_total": 543210, - "uuid": "bdf50b7d-4859-40af-8665-c637ee7a7808" + "uuid": "abcdef01-2345-6789-0abc-def012345678" }, "/boot": { "block_available": 2000, diff --git a/docs/docsite/rst/filter_guide_conversions.rst b/docs/docsite/rst/filter_guide_conversions.rst index ca0401762c..a1bb892802 100644 --- a/docs/docsite/rst/filter_guide_conversions.rst +++ b/docs/docsite/rst/filter_guide_conversions.rst @@ -24,6 +24,17 @@ Ansible offers the :ansplugin:`community.general.read_csv module { - "msg": "ff:69:d3:78:7f:b4" + "msg": "ff:84:f5:d1:59:20" } TASK [Create a random MAC starting with 00:11:22:] **************************************** ok: [localhost] => { - "msg": "00:11:22:71:5d:3b" + "msg": "00:11:22:84:f5:d1" } You can also initialize the random number generator from a seed to create random-but-idempotent MAC addresses: diff --git a/docs/docsite/rst/filter_guide_working_with_times.rst b/docs/docsite/rst/filter_guide_working_with_times.rst index 032d44bb57..76c7f1733c 100644 --- a/docs/docsite/rst/filter_guide_working_with_times.rst +++ b/docs/docsite/rst/filter_guide_working_with_times.rst @@ -69,21 +69,32 @@ Note that months and years are using a simplified representation: a month is 30 This produces: +.. ansible-output-data:: + + variables: + task: + previous_code_block: yaml+jinja + playbook: |- + - hosts: localhost + gather_facts: false + tasks: + @{{ task | indent(4) }}@ + .. code-block:: ansible-output TASK [Convert string to seconds] ********************************************************** ok: [localhost] => { - "msg": "109210.123" + "msg": 109210.123 } TASK [Convert string to hours] ************************************************************ ok: [localhost] => { - "msg": "30.336145277778" + "msg": 30.336145277778 } TASK [Convert string to years (using 365.25 days == 1 year)] ****************************** ok: [localhost] => { - "msg": "1.096851471595" + "msg": 1.096851471595 } .. versionadded: 0.2.0 diff --git a/docs/docsite/rst/filter_guide_working_with_unicode.rst b/docs/docsite/rst/filter_guide_working_with_unicode.rst index e75b0f871b..1c36d088d6 100644 --- a/docs/docsite/rst/filter_guide_working_with_unicode.rst +++ b/docs/docsite/rst/filter_guide_working_with_unicode.rst @@ -21,9 +21,20 @@ You can use the :ansplugin:`community.general.unicode_normalize filter { "msg": true } diff --git a/docs/docsite/rst/filter_guide_working_with_versions.rst b/docs/docsite/rst/filter_guide_working_with_versions.rst index 055bbcd217..39fd8e231b 100644 --- a/docs/docsite/rst/filter_guide_working_with_versions.rst +++ b/docs/docsite/rst/filter_guide_working_with_versions.rst @@ -23,6 +23,17 @@ If you need to sort a list of version numbers, the Jinja ``sort`` filter is prob This produces: +.. ansible-output-data:: + + variables: + task: + previous_code_block: yaml+jinja + playbook: |- + - hosts: localhost + gather_facts: false + tasks: + @{{ task | indent(4) }}@ + .. code-block:: ansible-output TASK [Sort list by version number] ******************************************************** diff --git a/noxfile.py b/noxfile.py index 9b2f92a9e1..c04c3e0d06 100644 --- a/noxfile.py +++ b/noxfile.py @@ -32,6 +32,18 @@ def botmeta(session: nox.Session) -> None: session.run("python", "tests/sanity/extra/botmeta.py") +@nox.session(name="ansible-output", default=False) +def ansible_output(session: nox.Session) -> None: + session.install( + "ansible-core", + "antsibull-docs", + # Needed libs for some code blocks: + "jc", + "hashids", + ) + session.run("antsibull-docs", "ansible-output", *session.posargs) + + # Allow to run the noxfile with `python noxfile.py`, `pipx run noxfile.py`, or similar. # Requires nox >= 2025.02.09 if __name__ == "__main__": From 0741b655901b439d103443bcecc29968ec3cbab1 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Sat, 19 Jul 2025 11:29:47 +0200 Subject: [PATCH 3/6] Generate YAML output as well. --- docs/docsite/config.yml | 5 + docs/docsite/reformat-yaml.py | 27 ++ ...ations-lists_of_dictionaries-keep_keys.rst | 97 +++++- ...ions-lists_of_dictionaries-remove_keys.rst | 99 +++++- ...ons-lists_of_dictionaries-replace_keys.rst | 132 ++++++- ...rmations_merging_lists_of_dictionaries.rst | 323 ++++++++++++++++-- noxfile.py | 2 + 7 files changed, 636 insertions(+), 49 deletions(-) create mode 100644 docs/docsite/reformat-yaml.py diff --git a/docs/docsite/config.yml b/docs/docsite/config.yml index 50b4a2f347..642bbe9bfd 100644 --- a/docs/docsite/config.yml +++ b/docs/docsite/config.yml @@ -10,3 +10,8 @@ ansible_output: global_env: ANSIBLE_STDOUT_CALLBACK: community.general.tasks_only ANSIBLE_COLLECTIONS_TASKS_ONLY_NUMBER_OF_COLUMNS: 90 + global_postprocessors: + reformat-yaml: + command: + - python + - docs/docsite/reformat-yaml.py diff --git a/docs/docsite/reformat-yaml.py b/docs/docsite/reformat-yaml.py new file mode 100644 index 0000000000..4e28526b82 --- /dev/null +++ b/docs/docsite/reformat-yaml.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python +# 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 + +import sys +from io import StringIO + +from ruamel.yaml import YAML + + +def main() -> None: + yaml = YAML(typ='rt') + yaml.indent(mapping=2, sequence=4, offset=2) + yaml.allow_duplicate_keys = True + + # Load + data = yaml.load(sys.stdin) + + # Dump + sio = StringIO() + yaml.dump(data, sio) + print(sio.getvalue().rstrip('\n')) + + +if __name__ == "__main__": + main() diff --git a/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-keep_keys.rst b/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-keep_keys.rst index 3549d29ba7..b16375a2fc 100644 --- a/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-keep_keys.rst +++ b/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-keep_keys.rst @@ -37,24 +37,80 @@ Let us use the below list in the following examples: gives +.. ansible-output-data:: + + env: + ANSIBLE_CALLBACK_RESULT_FORMAT: yaml + variables: + data: + previous_code_block: yaml + previous_code_block_index: 0 + computation: + previous_code_block: yaml+jinja + postprocessors: + - name: reformat-yaml + language: yaml + skip_first_lines: 2 + playbook: |- + - hosts: localhost + gather_facts: false + tasks: + - vars: + @{{ data | indent(8) }}@ + @{{ computation | indent(8) }}@ + ansible.builtin.debug: + var: result + .. code-block:: yaml :emphasize-lines: 1- result: - - {k0_x0: A0, k1_x1: B0} - - {k0_x0: A1, k1_x1: B1} + - k0_x0: A0 + k1_x1: B0 + - k0_x0: A1 + k1_x1: B1 .. versionadded:: 9.1.0 * The results of the below examples 1-5 are all the same: +.. ansible-output-data:: + + env: + ANSIBLE_CALLBACK_RESULT_FORMAT: yaml + variables: + data: + previous_code_block: yaml + previous_code_block_index: 0 + computation: + previous_code_block: yaml+jinja + postprocessors: + - name: reformat-yaml + language: yaml + skip_first_lines: 2 + playbook: |- + - hosts: localhost + gather_facts: false + tasks: + - vars: + @{{ data | indent(8) }}@ + + # I picked one of the examples + mp: equal + target: ['k0_x0', 'k1_x1'] + result: "{{ input | community.general.keep_keys(target=target, matching_parameter=mp) }}" + ansible.builtin.debug: + var: result + .. code-block:: yaml :emphasize-lines: 1- result: - - {k0_x0: A0, k1_x1: B0} - - {k0_x0: A1, k1_x1: B1} + - k0_x0: A0 + k1_x1: B0 + - k0_x0: A1 + k1_x1: B1 1. Match keys that equal any of the items in the target. @@ -105,12 +161,40 @@ gives * The results of the below examples 6-9 are all the same: +.. ansible-output-data:: + + env: + ANSIBLE_CALLBACK_RESULT_FORMAT: yaml + variables: + data: + previous_code_block: yaml + previous_code_block_index: 0 + computation: + previous_code_block: yaml+jinja + postprocessors: + - name: reformat-yaml + language: yaml + skip_first_lines: 2 + playbook: |- + - hosts: localhost + gather_facts: false + tasks: + - vars: + @{{ data | indent(8) }}@ + + # I picked one of the examples + mp: equal + target: k0_x0 + result: "{{ input | community.general.keep_keys(target=target, matching_parameter=mp) }}" + ansible.builtin.debug: + var: result + .. code-block:: yaml :emphasize-lines: 1- result: - - {k0_x0: A0} - - {k0_x0: A1} + - k0_x0: A0 + - k0_x0: A1 6. Match keys that equal the target. @@ -148,4 +232,3 @@ gives mp: regex target: ^.*0_x.*$ result: "{{ input | community.general.keep_keys(target=target, matching_parameter=mp) }}" - diff --git a/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-remove_keys.rst b/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-remove_keys.rst index 4ac87ab79c..068869bbbf 100644 --- a/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-remove_keys.rst +++ b/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-remove_keys.rst @@ -37,13 +37,39 @@ Let us use the below list in the following examples: gives +.. ansible-output-data:: + + env: + ANSIBLE_CALLBACK_RESULT_FORMAT: yaml + variables: + data: + previous_code_block: yaml + previous_code_block_index: 0 + computation: + previous_code_block: yaml+jinja + postprocessors: + - name: reformat-yaml + language: yaml + skip_first_lines: 2 + playbook: |- + - hosts: localhost + gather_facts: false + tasks: + - vars: + @{{ data | indent(8) }}@ + @{{ computation | indent(8) }}@ + ansible.builtin.debug: + var: result + .. code-block:: yaml :emphasize-lines: 1- result: - - k2_x2: [C0] + - k2_x2: + - C0 k3_x3: foo - - k2_x2: [C1] + - k2_x2: + - C1 k3_x3: bar @@ -51,13 +77,43 @@ gives * The results of the below examples 1-5 are all the same: +.. ansible-output-data:: + + env: + ANSIBLE_CALLBACK_RESULT_FORMAT: yaml + variables: + data: + previous_code_block: yaml + previous_code_block_index: 0 + computation: + previous_code_block: yaml+jinja + postprocessors: + - name: reformat-yaml + language: yaml + skip_first_lines: 2 + playbook: |- + - hosts: localhost + gather_facts: false + tasks: + - vars: + @{{ data | indent(8) }}@ + + # I picked one of the examples + mp: equal + target: ['k0_x0', 'k1_x1'] + result: "{{ input | community.general.remove_keys(target=target, matching_parameter=mp) }}" + ansible.builtin.debug: + var: result + .. code-block:: yaml :emphasize-lines: 1- result: - - k2_x2: [C0] + - k2_x2: + - C0 k3_x3: foo - - k2_x2: [C1] + - k2_x2: + - C1 k3_x3: bar @@ -109,15 +165,45 @@ gives * The results of the below examples 6-9 are all the same: +.. ansible-output-data:: + + env: + ANSIBLE_CALLBACK_RESULT_FORMAT: yaml + variables: + data: + previous_code_block: yaml + previous_code_block_index: 0 + computation: + previous_code_block: yaml+jinja + postprocessors: + - name: reformat-yaml + language: yaml + skip_first_lines: 2 + playbook: |- + - hosts: localhost + gather_facts: false + tasks: + - vars: + @{{ data | indent(8) }}@ + + # I picked one of the examples + mp: equal + target: k0_x0 + result: "{{ input | community.general.remove_keys(target=target, matching_parameter=mp) }}" + ansible.builtin.debug: + var: result + .. code-block:: yaml :emphasize-lines: 1- result: - k1_x1: B0 - k2_x2: [C0] + k2_x2: + - C0 k3_x3: foo - k1_x1: B1 - k2_x2: [C1] + k2_x2: + - C1 k3_x3: bar @@ -156,4 +242,3 @@ gives mp: regex target: ^.*0_x.*$ result: "{{ input | community.general.remove_keys(target=target, matching_parameter=mp) }}" - diff --git a/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-replace_keys.rst b/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-replace_keys.rst index d0eb202bfe..086d79b2a9 100644 --- a/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-replace_keys.rst +++ b/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-replace_keys.rst @@ -40,17 +40,43 @@ Let us use the below list in the following examples: gives +.. ansible-output-data:: + + env: + ANSIBLE_CALLBACK_RESULT_FORMAT: yaml + variables: + data: + previous_code_block: yaml + previous_code_block_index: 0 + computation: + previous_code_block: yaml+jinja + postprocessors: + - name: reformat-yaml + language: yaml + skip_first_lines: 2 + playbook: |- + - hosts: localhost + gather_facts: false + tasks: + - vars: + @{{ data | indent(8) }}@ + @{{ computation | indent(8) }}@ + ansible.builtin.debug: + var: result + .. code-block:: yaml :emphasize-lines: 1- result: - a0: A0 a1: B0 - k2_x2: [C0] + k2_x2: + - C0 k3_x3: foo - a0: A1 a1: B1 - k2_x2: [C1] + k2_x2: + - C1 k3_x3: bar @@ -58,17 +84,49 @@ gives * The results of the below examples 1-3 are all the same: +.. ansible-output-data:: + + env: + ANSIBLE_CALLBACK_RESULT_FORMAT: yaml + variables: + data: + previous_code_block: yaml + previous_code_block_index: 0 + computation: + previous_code_block: yaml+jinja + postprocessors: + - name: reformat-yaml + language: yaml + skip_first_lines: 2 + playbook: |- + - hosts: localhost + gather_facts: false + tasks: + - vars: + @{{ data | indent(8) }}@ + + # I picked one of the examples + mp: starts_with + target: + - {after: a0, before: k0} + - {after: a1, before: k1} + result: "{{ input | community.general.replace_keys(target=target, matching_parameter=mp) }}" + ansible.builtin.debug: + var: result + .. code-block:: yaml :emphasize-lines: 1- result: - a0: A0 a1: B0 - k2_x2: [C0] + k2_x2: + - C0 k3_x3: foo - a0: A1 a1: B1 - k2_x2: [C1] + k2_x2: + - C1 k3_x3: bar @@ -111,12 +169,41 @@ gives * The results of the below examples 4-5 are the same: +.. ansible-output-data:: + + env: + ANSIBLE_CALLBACK_RESULT_FORMAT: yaml + variables: + data: + previous_code_block: yaml + previous_code_block_index: 0 + computation: + previous_code_block: yaml+jinja + postprocessors: + - name: reformat-yaml + language: yaml + skip_first_lines: 2 + playbook: |- + - hosts: localhost + gather_facts: false + tasks: + - vars: + @{{ data | indent(8) }}@ + + # I picked one of the examples + mp: regex + target: + - {after: X, before: ^.*_x.*$} + result: "{{ input | community.general.replace_keys(target=target, matching_parameter=mp) }}" + ansible.builtin.debug: + var: result + .. code-block:: yaml :emphasize-lines: 1- result: - - {X: foo} - - {X: bar} + - X: foo + - X: bar 4. If more keys match the same attribute before the last one will be used. @@ -165,11 +252,36 @@ gives gives +.. ansible-output-data:: + + env: + ANSIBLE_CALLBACK_RESULT_FORMAT: yaml + variables: + data: + previous_code_block: yaml + computation: + previous_code_block: yaml+jinja + postprocessors: + - name: reformat-yaml + language: yaml + skip_first_lines: 2 + playbook: |- + - hosts: localhost + gather_facts: false + tasks: + - vars: + @{{ data | indent(8) }}@ + @{{ computation | indent(8) }}@ + ansible.builtin.debug: + var: result + .. code-block:: yaml :emphasize-lines: 1- result: - - {X: A, bbb1: B, ccc1: C} - - {X: D, bbb2: E, ccc2: F} - - + - X: A + bbb1: B + ccc1: C + - X: D + bbb2: E + ccc2: F diff --git a/docs/docsite/rst/filter_guide_abstract_informations_merging_lists_of_dictionaries.rst b/docs/docsite/rst/filter_guide_abstract_informations_merging_lists_of_dictionaries.rst index cafe04e5c4..330020c2bb 100644 --- a/docs/docsite/rst/filter_guide_abstract_informations_merging_lists_of_dictionaries.rst +++ b/docs/docsite/rst/filter_guide_abstract_informations_merging_lists_of_dictionaries.rst @@ -34,13 +34,42 @@ In the example below the lists are merged by the attribute ``name``: This produces: +.. ansible-output-data:: + + env: + ANSIBLE_CALLBACK_RESULT_FORMAT: yaml + variables: + data: + previous_code_block: yaml + previous_code_block_index: 0 + computation: + previous_code_block: yaml+jinja + postprocessors: + - name: reformat-yaml + language: yaml + skip_first_lines: 2 + playbook: |- + - hosts: localhost + gather_facts: false + tasks: + - vars: + @{{ data | indent(8) }}@ + @{{ computation | indent(8) }}@ + ansible.builtin.debug: + var: list3 + .. code-block:: yaml list3: - - {name: bar, extra: false} - - {name: baz, path: /baz} - - {name: foo, extra: true, path: /foo} - - {name: meh, extra: true} + - extra: false + name: bar + - name: baz + path: /baz + - extra: true + name: foo + path: /foo + - extra: true + name: meh .. versionadded:: 2.0.0 @@ -56,13 +85,42 @@ It is possible to use a list of lists as an input of the filter: This produces the same result as in the previous example: +.. ansible-output-data:: + + env: + ANSIBLE_CALLBACK_RESULT_FORMAT: yaml + variables: + data: + previous_code_block: yaml + previous_code_block_index: 0 + computation: + previous_code_block: yaml+jinja + postprocessors: + - name: reformat-yaml + language: yaml + skip_first_lines: 2 + playbook: |- + - hosts: localhost + gather_facts: false + tasks: + - vars: + @{{ data | indent(8) }}@ + @{{ computation | indent(8) }}@ + ansible.builtin.debug: + var: list3 + .. code-block:: yaml list3: - - {name: bar, extra: false} - - {name: baz, path: /baz} - - {name: foo, extra: true, path: /foo} - - {name: meh, extra: true} + - extra: false + name: bar + - name: baz + path: /baz + - extra: true + name: foo + path: /foo + - extra: true + name: meh Single list """"""""""" @@ -75,13 +133,42 @@ It is possible to merge single list: This produces the same result as in the previous example: +.. ansible-output-data:: + + env: + ANSIBLE_CALLBACK_RESULT_FORMAT: yaml + variables: + data: + previous_code_block: yaml + previous_code_block_index: 0 + computation: + previous_code_block: yaml+jinja + postprocessors: + - name: reformat-yaml + language: yaml + skip_first_lines: 2 + playbook: |- + - hosts: localhost + gather_facts: false + tasks: + - vars: + @{{ data | indent(8) }}@ + @{{ computation | indent(8) }}@ + ansible.builtin.debug: + var: list3 + .. code-block:: yaml list3: - - {name: bar, extra: false} - - {name: baz, path: /baz} - - {name: foo, extra: true, path: /foo} - - {name: meh, extra: true} + - extra: false + name: bar + - name: baz + path: /baz + - extra: true + name: foo + path: /foo + - extra: true + name: meh The filter also accepts two optional parameters: :ansopt:`community.general.lists_mergeby#filter:recursive` and :ansopt:`community.general.lists_mergeby#filter:list_merge`. This is available since community.general 4.4.0. @@ -128,17 +215,45 @@ Example :ansopt:`community.general.lists_mergeby#filter:list_merge=replace` (def This produces: +.. ansible-output-data:: + + env: + ANSIBLE_CALLBACK_RESULT_FORMAT: yaml + variables: + data: + previous_code_block: yaml + previous_code_block_index: 4 + computation: + previous_code_block: yaml+jinja + postprocessors: + - name: reformat-yaml + language: yaml + skip_first_lines: 2 + playbook: |- + - hosts: localhost + gather_facts: false + tasks: + - vars: + @{{ data | indent(8) }}@ + @{{ computation | indent(8) }}@ + ansible.builtin.debug: + var: list3 + .. code-block:: yaml list3: - name: myname01 param01: + list: + - patch_value x: default_value y: patch_value - list: [patch_value] z: patch_value - name: myname02 - param01: [3, 4, 4] + param01: + - 3 + - 4 + - 4 list_merge=keep """"""""""""""" @@ -153,17 +268,46 @@ Example :ansopt:`community.general.lists_mergeby#filter:list_merge=keep`: This produces: +.. ansible-output-data:: + + env: + ANSIBLE_CALLBACK_RESULT_FORMAT: yaml + variables: + data: + previous_code_block: yaml + previous_code_block_index: 4 + computation: + previous_code_block: yaml+jinja + postprocessors: + - name: reformat-yaml + language: yaml + skip_first_lines: 2 + playbook: |- + - hosts: localhost + gather_facts: false + tasks: + - vars: + @{{ data | indent(8) }}@ + @{{ computation | indent(8) }}@ + ansible.builtin.debug: + var: list3 + .. code-block:: yaml list3: - name: myname01 param01: + list: + - default_value x: default_value y: patch_value - list: [default_value] z: patch_value - name: myname02 - param01: [1, 1, 2, 3] + param01: + - 1 + - 1 + - 2 + - 3 list_merge=append """"""""""""""""" @@ -178,17 +322,50 @@ Example :ansopt:`community.general.lists_mergeby#filter:list_merge=append`: This produces: +.. ansible-output-data:: + + env: + ANSIBLE_CALLBACK_RESULT_FORMAT: yaml + variables: + data: + previous_code_block: yaml + previous_code_block_index: 4 + computation: + previous_code_block: yaml+jinja + postprocessors: + - name: reformat-yaml + language: yaml + skip_first_lines: 2 + playbook: |- + - hosts: localhost + gather_facts: false + tasks: + - vars: + @{{ data | indent(8) }}@ + @{{ computation | indent(8) }}@ + ansible.builtin.debug: + var: list3 + .. code-block:: yaml list3: - name: myname01 param01: + list: + - default_value + - patch_value x: default_value y: patch_value - list: [default_value, patch_value] z: patch_value - name: myname02 - param01: [1, 1, 2, 3, 3, 4, 4] + param01: + - 1 + - 1 + - 2 + - 3 + - 3 + - 4 + - 4 list_merge=prepend """""""""""""""""" @@ -203,17 +380,50 @@ Example :ansopt:`community.general.lists_mergeby#filter:list_merge=prepend`: This produces: +.. ansible-output-data:: + + env: + ANSIBLE_CALLBACK_RESULT_FORMAT: yaml + variables: + data: + previous_code_block: yaml + previous_code_block_index: 4 + computation: + previous_code_block: yaml+jinja + postprocessors: + - name: reformat-yaml + language: yaml + skip_first_lines: 2 + playbook: |- + - hosts: localhost + gather_facts: false + tasks: + - vars: + @{{ data | indent(8) }}@ + @{{ computation | indent(8) }}@ + ansible.builtin.debug: + var: list3 + .. code-block:: yaml list3: - name: myname01 param01: + list: + - patch_value + - default_value x: default_value y: patch_value - list: [patch_value, default_value] z: patch_value - name: myname02 - param01: [3, 4, 4, 1, 1, 2, 3] + param01: + - 3 + - 4 + - 4 + - 1 + - 1 + - 2 + - 3 list_merge=append_rp """""""""""""""""""" @@ -228,17 +438,49 @@ Example :ansopt:`community.general.lists_mergeby#filter:list_merge=append_rp`: This produces: +.. ansible-output-data:: + + env: + ANSIBLE_CALLBACK_RESULT_FORMAT: yaml + variables: + data: + previous_code_block: yaml + previous_code_block_index: 4 + computation: + previous_code_block: yaml+jinja + postprocessors: + - name: reformat-yaml + language: yaml + skip_first_lines: 2 + playbook: |- + - hosts: localhost + gather_facts: false + tasks: + - vars: + @{{ data | indent(8) }}@ + @{{ computation | indent(8) }}@ + ansible.builtin.debug: + var: list3 + .. code-block:: yaml list3: - name: myname01 param01: + list: + - default_value + - patch_value x: default_value y: patch_value - list: [default_value, patch_value] z: patch_value - name: myname02 - param01: [1, 1, 2, 3, 4, 4] + param01: + - 1 + - 1 + - 2 + - 3 + - 4 + - 4 list_merge=prepend_rp """"""""""""""""""""" @@ -253,15 +495,46 @@ Example :ansopt:`community.general.lists_mergeby#filter:list_merge=prepend_rp`: This produces: +.. ansible-output-data:: + + env: + ANSIBLE_CALLBACK_RESULT_FORMAT: yaml + variables: + data: + previous_code_block: yaml + previous_code_block_index: 4 + computation: + previous_code_block: yaml+jinja + postprocessors: + - name: reformat-yaml + language: yaml + skip_first_lines: 2 + playbook: |- + - hosts: localhost + gather_facts: false + tasks: + - vars: + @{{ data | indent(8) }}@ + @{{ computation | indent(8) }}@ + ansible.builtin.debug: + var: list3 + .. code-block:: yaml list3: - name: myname01 param01: + list: + - patch_value + - default_value x: default_value y: patch_value - list: [patch_value, default_value] z: patch_value - name: myname02 - param01: [3, 4, 4, 1, 1, 2] - + param01: + - 3 + - 4 + - 4 + - 1 + - 1 + - 2 diff --git a/noxfile.py b/noxfile.py index c04c3e0d06..ffeda8013f 100644 --- a/noxfile.py +++ b/noxfile.py @@ -40,6 +40,8 @@ def ansible_output(session: nox.Session) -> None: # Needed libs for some code blocks: "jc", "hashids", + # Tools for post-processing + "ruamel.yaml", # used by docs/docsite/reformat-yaml.py ) session.run("antsibull-docs", "ansible-output", *session.posargs) From 6d60fd4f7ea8f35daa7d20880a4761d2ade59b55 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Sat, 19 Jul 2025 12:17:03 +0200 Subject: [PATCH 4/6] Check ansible-output from CI instead of updating. --- noxfile.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/noxfile.py b/noxfile.py index ffeda8013f..dc1899a407 100644 --- a/noxfile.py +++ b/noxfile.py @@ -6,10 +6,14 @@ # dependencies = ["nox>=2025.02.09", "antsibull-nox"] # /// +import os import sys import nox +# Whether the noxfile is running in CI: +IN_CI = os.environ.get("CI") == "true" + try: import antsibull_nox @@ -43,7 +47,10 @@ def ansible_output(session: nox.Session) -> None: # Tools for post-processing "ruamel.yaml", # used by docs/docsite/reformat-yaml.py ) - session.run("antsibull-docs", "ansible-output", *session.posargs) + args = [] + if IN_CI: + args.append("--check") + session.run("antsibull-docs", "ansible-output", *args, *session.posargs) # Allow to run the noxfile with `python noxfile.py`, `pipx run noxfile.py`, or similar. From 8d6e58f2c8c41bc91420bdadcc873b8ac4ef6cad Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Sun, 20 Jul 2025 14:35:59 +0200 Subject: [PATCH 5/6] Use reset-previous-blocks meta action; generate more code blocks. --- ...ations-lists_of_dictionaries-keep_keys.rst | 5 + ...ions-lists_of_dictionaries-remove_keys.rst | 5 + ...ons-lists_of_dictionaries-replace_keys.rst | 5 + ...ide_abstract_informations_lists_helper.rst | 98 ++++++++++++++++++- ...rmations_merging_lists_of_dictionaries.rst | 22 +++-- 5 files changed, 125 insertions(+), 10 deletions(-) diff --git a/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-keep_keys.rst b/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-keep_keys.rst index b16375a2fc..fc68060b49 100644 --- a/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-keep_keys.rst +++ b/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-keep_keys.rst @@ -13,6 +13,11 @@ Use the filter :ansplugin:`community.general.keep_keys#filter` if you have a lis Let us use the below list in the following examples: +.. ansible-output-meta:: + + actions: + - name: reset-previous-blocks + .. code-block:: yaml input: diff --git a/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-remove_keys.rst b/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-remove_keys.rst index 068869bbbf..adb5fcdae0 100644 --- a/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-remove_keys.rst +++ b/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-remove_keys.rst @@ -13,6 +13,11 @@ Use the filter :ansplugin:`community.general.remove_keys#filter` if you have a l Let us use the below list in the following examples: +.. ansible-output-meta:: + + actions: + - name: reset-previous-blocks + .. code-block:: yaml input: diff --git a/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-replace_keys.rst b/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-replace_keys.rst index 086d79b2a9..9c114d23f3 100644 --- a/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-replace_keys.rst +++ b/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-replace_keys.rst @@ -13,6 +13,11 @@ Use the filter :ansplugin:`community.general.replace_keys#filter` if you have a Let us use the below list in the following examples: +.. ansible-output-meta:: + + actions: + - name: reset-previous-blocks + .. code-block:: yaml input: diff --git a/docs/docsite/rst/filter_guide_abstract_informations_lists_helper.rst b/docs/docsite/rst/filter_guide_abstract_informations_lists_helper.rst index 505320c79c..afeebbcc9f 100644 --- a/docs/docsite/rst/filter_guide_abstract_informations_lists_helper.rst +++ b/docs/docsite/rst/filter_guide_abstract_informations_lists_helper.rst @@ -21,6 +21,11 @@ These filters preserve the item order, eliminate duplicates and are an extended Let us use the lists below in the following examples: +.. ansible-output-meta:: + + actions: + - name: reset-previous-blocks + .. code-block:: yaml A: [9, 5, 7, 1, 9, 4, 10, 5, 9, 7] @@ -35,9 +40,42 @@ The union of ``A`` and ``B`` can be written as: This statement produces: +.. ansible-output-data:: + + env: + ANSIBLE_CALLBACK_RESULT_FORMAT: yaml + variables: + data: + previous_code_block: yaml + previous_code_block_index: 0 + computation: + previous_code_block: yaml+jinja + postprocessors: + - name: reformat-yaml + language: yaml + skip_first_lines: 2 + playbook: |- + - hosts: localhost + gather_facts: false + tasks: + - vars: + @{{ data | indent(8) }}@ + @{{ computation | indent(8) }}@ + ansible.builtin.debug: + var: result + .. code-block:: yaml - result: [9, 5, 7, 1, 4, 10, 2, 8, 3] + result: + - 9 + - 5 + - 7 + - 1 + - 4 + - 10 + - 2 + - 8 + - 3 If you want to calculate the intersection of ``A``, ``B`` and ``C``, you can use the following statement: @@ -59,9 +97,34 @@ or All three statements are equivalent and give: +.. ansible-output-data:: + + env: + ANSIBLE_CALLBACK_RESULT_FORMAT: yaml + variables: + data: + previous_code_block: yaml + previous_code_block_index: 0 + computation: + previous_code_block: yaml+jinja + postprocessors: + - name: reformat-yaml + language: yaml + skip_first_lines: 2 + playbook: |- + - hosts: localhost + gather_facts: false + tasks: + - vars: + @{{ data | indent(8) }}@ + @{{ computation | indent(8) }}@ + ansible.builtin.debug: + var: result + .. code-block:: yaml - result: [1] + result: + - 1 .. note:: Be aware that in most cases, filter calls without any argument require ``flatten=true``, otherwise the input is returned as result. The reason for this is, that the input is considered as a variable argument and is wrapped by an additional outer list. ``flatten=true`` ensures that this list is removed before the input is processed by the filter logic. @@ -75,7 +138,34 @@ For example, the symmetric difference of ``A``, ``B`` and ``C`` may be written a This gives: +.. ansible-output-data:: + + env: + ANSIBLE_CALLBACK_RESULT_FORMAT: yaml + variables: + data: + previous_code_block: yaml + previous_code_block_index: 0 + computation: + previous_code_block: yaml+jinja + postprocessors: + - name: reformat-yaml + language: yaml + skip_first_lines: 2 + playbook: |- + - hosts: localhost + gather_facts: false + tasks: + - vars: + @{{ data | indent(8) }}@ + @{{ computation | indent(8) }}@ + ansible.builtin.debug: + var: result + .. code-block:: yaml - result: [5, 8, 3, 1] - + result: + - 5 + - 8 + - 3 + - 1 diff --git a/docs/docsite/rst/filter_guide_abstract_informations_merging_lists_of_dictionaries.rst b/docs/docsite/rst/filter_guide_abstract_informations_merging_lists_of_dictionaries.rst index 330020c2bb..48189fb042 100644 --- a/docs/docsite/rst/filter_guide_abstract_informations_merging_lists_of_dictionaries.rst +++ b/docs/docsite/rst/filter_guide_abstract_informations_merging_lists_of_dictionaries.rst @@ -12,6 +12,11 @@ If you have two or more lists of dictionaries and want to combine them into a li Let us use the lists below in the following examples: +.. ansible-output-meta:: + + actions: + - name: reset-previous-blocks + .. code-block:: yaml list1: @@ -183,6 +188,11 @@ The examples below set :ansopt:`community.general.lists_mergeby#filter:recursive Let us use the lists below in the following examples +.. ansible-output-meta:: + + actions: + - name: reset-previous-blocks + .. code-block:: yaml list1: @@ -222,7 +232,7 @@ This produces: variables: data: previous_code_block: yaml - previous_code_block_index: 4 + previous_code_block_index: 0 computation: previous_code_block: yaml+jinja postprocessors: @@ -275,7 +285,7 @@ This produces: variables: data: previous_code_block: yaml - previous_code_block_index: 4 + previous_code_block_index: 0 computation: previous_code_block: yaml+jinja postprocessors: @@ -329,7 +339,7 @@ This produces: variables: data: previous_code_block: yaml - previous_code_block_index: 4 + previous_code_block_index: 0 computation: previous_code_block: yaml+jinja postprocessors: @@ -387,7 +397,7 @@ This produces: variables: data: previous_code_block: yaml - previous_code_block_index: 4 + previous_code_block_index: 0 computation: previous_code_block: yaml+jinja postprocessors: @@ -445,7 +455,7 @@ This produces: variables: data: previous_code_block: yaml - previous_code_block_index: 4 + previous_code_block_index: 0 computation: previous_code_block: yaml+jinja postprocessors: @@ -502,7 +512,7 @@ This produces: variables: data: previous_code_block: yaml - previous_code_block_index: 4 + previous_code_block_index: 0 computation: previous_code_block: yaml+jinja postprocessors: From 3c165c8fc927ce9c4d8e6148d940d9611e8f2007 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Sun, 20 Jul 2025 15:22:24 +0200 Subject: [PATCH 6/6] Use set-template meta action. --- ...ations-lists_of_dictionaries-keep_keys.rst | 69 ++---- ...ions-lists_of_dictionaries-remove_keys.rst | 69 ++---- ...ons-lists_of_dictionaries-replace_keys.rst | 95 +++----- ...ide_abstract_informations_lists_helper.rst | 89 +++---- ...rmations_merging_lists_of_dictionaries.rst | 221 +++--------------- 5 files changed, 136 insertions(+), 407 deletions(-) diff --git a/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-keep_keys.rst b/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-keep_keys.rst index fc68060b49..fcaddaf922 100644 --- a/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-keep_keys.rst +++ b/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-keep_keys.rst @@ -17,6 +17,29 @@ Let us use the below list in the following examples: actions: - name: reset-previous-blocks + - name: set-template + template: + env: + ANSIBLE_CALLBACK_RESULT_FORMAT: yaml + variables: + data: + previous_code_block: yaml + previous_code_block_index: 0 + computation: + previous_code_block: yaml+jinja + postprocessors: + - name: reformat-yaml + language: yaml + skip_first_lines: 2 + playbook: |- + - hosts: localhost + gather_facts: false + tasks: + - vars: + @{{ data | indent(8) }}@ + @{{ computation | indent(8) }}@ + ansible.builtin.debug: + var: result .. code-block:: yaml @@ -44,27 +67,7 @@ gives .. ansible-output-data:: - env: - ANSIBLE_CALLBACK_RESULT_FORMAT: yaml - variables: - data: - previous_code_block: yaml - previous_code_block_index: 0 - computation: - previous_code_block: yaml+jinja - postprocessors: - - name: reformat-yaml - language: yaml - skip_first_lines: 2 - playbook: |- - - hosts: localhost - gather_facts: false - tasks: - - vars: - @{{ data | indent(8) }}@ - @{{ computation | indent(8) }}@ - ansible.builtin.debug: - var: result + playbook: ~ .. code-block:: yaml :emphasize-lines: 1- @@ -82,18 +85,6 @@ gives .. ansible-output-data:: - env: - ANSIBLE_CALLBACK_RESULT_FORMAT: yaml - variables: - data: - previous_code_block: yaml - previous_code_block_index: 0 - computation: - previous_code_block: yaml+jinja - postprocessors: - - name: reformat-yaml - language: yaml - skip_first_lines: 2 playbook: |- - hosts: localhost gather_facts: false @@ -168,18 +159,6 @@ gives .. ansible-output-data:: - env: - ANSIBLE_CALLBACK_RESULT_FORMAT: yaml - variables: - data: - previous_code_block: yaml - previous_code_block_index: 0 - computation: - previous_code_block: yaml+jinja - postprocessors: - - name: reformat-yaml - language: yaml - skip_first_lines: 2 playbook: |- - hosts: localhost gather_facts: false diff --git a/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-remove_keys.rst b/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-remove_keys.rst index adb5fcdae0..6477b5fb41 100644 --- a/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-remove_keys.rst +++ b/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-remove_keys.rst @@ -17,6 +17,29 @@ Let us use the below list in the following examples: actions: - name: reset-previous-blocks + - name: set-template + template: + env: + ANSIBLE_CALLBACK_RESULT_FORMAT: yaml + variables: + data: + previous_code_block: yaml + previous_code_block_index: 0 + computation: + previous_code_block: yaml+jinja + postprocessors: + - name: reformat-yaml + language: yaml + skip_first_lines: 2 + playbook: |- + - hosts: localhost + gather_facts: false + tasks: + - vars: + @{{ data | indent(8) }}@ + @{{ computation | indent(8) }}@ + ansible.builtin.debug: + var: result .. code-block:: yaml @@ -44,27 +67,7 @@ gives .. ansible-output-data:: - env: - ANSIBLE_CALLBACK_RESULT_FORMAT: yaml - variables: - data: - previous_code_block: yaml - previous_code_block_index: 0 - computation: - previous_code_block: yaml+jinja - postprocessors: - - name: reformat-yaml - language: yaml - skip_first_lines: 2 - playbook: |- - - hosts: localhost - gather_facts: false - tasks: - - vars: - @{{ data | indent(8) }}@ - @{{ computation | indent(8) }}@ - ansible.builtin.debug: - var: result + playbook: ~ .. code-block:: yaml :emphasize-lines: 1- @@ -84,18 +87,6 @@ gives .. ansible-output-data:: - env: - ANSIBLE_CALLBACK_RESULT_FORMAT: yaml - variables: - data: - previous_code_block: yaml - previous_code_block_index: 0 - computation: - previous_code_block: yaml+jinja - postprocessors: - - name: reformat-yaml - language: yaml - skip_first_lines: 2 playbook: |- - hosts: localhost gather_facts: false @@ -172,18 +163,6 @@ gives .. ansible-output-data:: - env: - ANSIBLE_CALLBACK_RESULT_FORMAT: yaml - variables: - data: - previous_code_block: yaml - previous_code_block_index: 0 - computation: - previous_code_block: yaml+jinja - postprocessors: - - name: reformat-yaml - language: yaml - skip_first_lines: 2 playbook: |- - hosts: localhost gather_facts: false diff --git a/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-replace_keys.rst b/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-replace_keys.rst index 9c114d23f3..e23439917d 100644 --- a/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-replace_keys.rst +++ b/docs/docsite/rst/filter_guide-abstract_informations-lists_of_dictionaries-replace_keys.rst @@ -17,6 +17,29 @@ Let us use the below list in the following examples: actions: - name: reset-previous-blocks + - name: set-template + template: + env: + ANSIBLE_CALLBACK_RESULT_FORMAT: yaml + variables: + data: + previous_code_block: yaml + previous_code_block_index: 0 + computation: + previous_code_block: yaml+jinja + postprocessors: + - name: reformat-yaml + language: yaml + skip_first_lines: 2 + playbook: |- + - hosts: localhost + gather_facts: false + tasks: + - vars: + @{{ data | indent(8) }}@ + @{{ computation | indent(8) }}@ + ansible.builtin.debug: + var: result .. code-block:: yaml @@ -47,27 +70,7 @@ gives .. ansible-output-data:: - env: - ANSIBLE_CALLBACK_RESULT_FORMAT: yaml - variables: - data: - previous_code_block: yaml - previous_code_block_index: 0 - computation: - previous_code_block: yaml+jinja - postprocessors: - - name: reformat-yaml - language: yaml - skip_first_lines: 2 - playbook: |- - - hosts: localhost - gather_facts: false - tasks: - - vars: - @{{ data | indent(8) }}@ - @{{ computation | indent(8) }}@ - ansible.builtin.debug: - var: result + playbook: ~ .. code-block:: yaml :emphasize-lines: 1- @@ -91,18 +94,6 @@ gives .. ansible-output-data:: - env: - ANSIBLE_CALLBACK_RESULT_FORMAT: yaml - variables: - data: - previous_code_block: yaml - previous_code_block_index: 0 - computation: - previous_code_block: yaml+jinja - postprocessors: - - name: reformat-yaml - language: yaml - skip_first_lines: 2 playbook: |- - hosts: localhost gather_facts: false @@ -176,18 +167,6 @@ gives .. ansible-output-data:: - env: - ANSIBLE_CALLBACK_RESULT_FORMAT: yaml - variables: - data: - previous_code_block: yaml - previous_code_block_index: 0 - computation: - previous_code_block: yaml+jinja - postprocessors: - - name: reformat-yaml - language: yaml - skip_first_lines: 2 playbook: |- - hosts: localhost gather_facts: false @@ -237,6 +216,11 @@ gives 6. If there are more matches for a key the first one will be used. +.. ansible-output-meta:: + + actions: + - name: reset-previous-blocks + .. code-block:: yaml :emphasize-lines: 1- @@ -259,26 +243,7 @@ gives .. ansible-output-data:: - env: - ANSIBLE_CALLBACK_RESULT_FORMAT: yaml - variables: - data: - previous_code_block: yaml - computation: - previous_code_block: yaml+jinja - postprocessors: - - name: reformat-yaml - language: yaml - skip_first_lines: 2 - playbook: |- - - hosts: localhost - gather_facts: false - tasks: - - vars: - @{{ data | indent(8) }}@ - @{{ computation | indent(8) }}@ - ansible.builtin.debug: - var: result + playbook: ~ .. code-block:: yaml :emphasize-lines: 1- diff --git a/docs/docsite/rst/filter_guide_abstract_informations_lists_helper.rst b/docs/docsite/rst/filter_guide_abstract_informations_lists_helper.rst index afeebbcc9f..5e3a32488a 100644 --- a/docs/docsite/rst/filter_guide_abstract_informations_lists_helper.rst +++ b/docs/docsite/rst/filter_guide_abstract_informations_lists_helper.rst @@ -25,6 +25,29 @@ Let us use the lists below in the following examples: actions: - name: reset-previous-blocks + - name: set-template + template: + env: + ANSIBLE_CALLBACK_RESULT_FORMAT: yaml + variables: + data: + previous_code_block: yaml + previous_code_block_index: 0 + computation: + previous_code_block: yaml+jinja + postprocessors: + - name: reformat-yaml + language: yaml + skip_first_lines: 2 + playbook: |- + - hosts: localhost + gather_facts: false + tasks: + - vars: + @{{ data | indent(8) }}@ + @{{ computation | indent(8) }}@ + ansible.builtin.debug: + var: result .. code-block:: yaml @@ -42,27 +65,7 @@ This statement produces: .. ansible-output-data:: - env: - ANSIBLE_CALLBACK_RESULT_FORMAT: yaml - variables: - data: - previous_code_block: yaml - previous_code_block_index: 0 - computation: - previous_code_block: yaml+jinja - postprocessors: - - name: reformat-yaml - language: yaml - skip_first_lines: 2 - playbook: |- - - hosts: localhost - gather_facts: false - tasks: - - vars: - @{{ data | indent(8) }}@ - @{{ computation | indent(8) }}@ - ansible.builtin.debug: - var: result + playbook: ~ .. code-block:: yaml @@ -99,27 +102,7 @@ All three statements are equivalent and give: .. ansible-output-data:: - env: - ANSIBLE_CALLBACK_RESULT_FORMAT: yaml - variables: - data: - previous_code_block: yaml - previous_code_block_index: 0 - computation: - previous_code_block: yaml+jinja - postprocessors: - - name: reformat-yaml - language: yaml - skip_first_lines: 2 - playbook: |- - - hosts: localhost - gather_facts: false - tasks: - - vars: - @{{ data | indent(8) }}@ - @{{ computation | indent(8) }}@ - ansible.builtin.debug: - var: result + playbook: ~ .. code-block:: yaml @@ -140,27 +123,7 @@ This gives: .. ansible-output-data:: - env: - ANSIBLE_CALLBACK_RESULT_FORMAT: yaml - variables: - data: - previous_code_block: yaml - previous_code_block_index: 0 - computation: - previous_code_block: yaml+jinja - postprocessors: - - name: reformat-yaml - language: yaml - skip_first_lines: 2 - playbook: |- - - hosts: localhost - gather_facts: false - tasks: - - vars: - @{{ data | indent(8) }}@ - @{{ computation | indent(8) }}@ - ansible.builtin.debug: - var: result + playbook: ~ .. code-block:: yaml diff --git a/docs/docsite/rst/filter_guide_abstract_informations_merging_lists_of_dictionaries.rst b/docs/docsite/rst/filter_guide_abstract_informations_merging_lists_of_dictionaries.rst index 48189fb042..9b4f7a96f3 100644 --- a/docs/docsite/rst/filter_guide_abstract_informations_merging_lists_of_dictionaries.rst +++ b/docs/docsite/rst/filter_guide_abstract_informations_merging_lists_of_dictionaries.rst @@ -16,6 +16,29 @@ Let us use the lists below in the following examples: actions: - name: reset-previous-blocks + - name: set-template + template: + env: + ANSIBLE_CALLBACK_RESULT_FORMAT: yaml + variables: + data: + previous_code_block: yaml + previous_code_block_index: 0 + computation: + previous_code_block: yaml+jinja + postprocessors: + - name: reformat-yaml + language: yaml + skip_first_lines: 2 + playbook: |- + - hosts: localhost + gather_facts: false + tasks: + - vars: + @{{ data | indent(8) }}@ + @{{ computation | indent(8) }}@ + ansible.builtin.debug: + var: list3 .. code-block:: yaml @@ -41,27 +64,7 @@ This produces: .. ansible-output-data:: - env: - ANSIBLE_CALLBACK_RESULT_FORMAT: yaml - variables: - data: - previous_code_block: yaml - previous_code_block_index: 0 - computation: - previous_code_block: yaml+jinja - postprocessors: - - name: reformat-yaml - language: yaml - skip_first_lines: 2 - playbook: |- - - hosts: localhost - gather_facts: false - tasks: - - vars: - @{{ data | indent(8) }}@ - @{{ computation | indent(8) }}@ - ansible.builtin.debug: - var: list3 + playbook: ~ .. code-block:: yaml @@ -92,27 +95,7 @@ This produces the same result as in the previous example: .. ansible-output-data:: - env: - ANSIBLE_CALLBACK_RESULT_FORMAT: yaml - variables: - data: - previous_code_block: yaml - previous_code_block_index: 0 - computation: - previous_code_block: yaml+jinja - postprocessors: - - name: reformat-yaml - language: yaml - skip_first_lines: 2 - playbook: |- - - hosts: localhost - gather_facts: false - tasks: - - vars: - @{{ data | indent(8) }}@ - @{{ computation | indent(8) }}@ - ansible.builtin.debug: - var: list3 + playbook: ~ .. code-block:: yaml @@ -140,27 +123,7 @@ This produces the same result as in the previous example: .. ansible-output-data:: - env: - ANSIBLE_CALLBACK_RESULT_FORMAT: yaml - variables: - data: - previous_code_block: yaml - previous_code_block_index: 0 - computation: - previous_code_block: yaml+jinja - postprocessors: - - name: reformat-yaml - language: yaml - skip_first_lines: 2 - playbook: |- - - hosts: localhost - gather_facts: false - tasks: - - vars: - @{{ data | indent(8) }}@ - @{{ computation | indent(8) }}@ - ansible.builtin.debug: - var: list3 + playbook: ~ .. code-block:: yaml @@ -227,27 +190,7 @@ This produces: .. ansible-output-data:: - env: - ANSIBLE_CALLBACK_RESULT_FORMAT: yaml - variables: - data: - previous_code_block: yaml - previous_code_block_index: 0 - computation: - previous_code_block: yaml+jinja - postprocessors: - - name: reformat-yaml - language: yaml - skip_first_lines: 2 - playbook: |- - - hosts: localhost - gather_facts: false - tasks: - - vars: - @{{ data | indent(8) }}@ - @{{ computation | indent(8) }}@ - ansible.builtin.debug: - var: list3 + playbook: ~ .. code-block:: yaml @@ -280,27 +223,7 @@ This produces: .. ansible-output-data:: - env: - ANSIBLE_CALLBACK_RESULT_FORMAT: yaml - variables: - data: - previous_code_block: yaml - previous_code_block_index: 0 - computation: - previous_code_block: yaml+jinja - postprocessors: - - name: reformat-yaml - language: yaml - skip_first_lines: 2 - playbook: |- - - hosts: localhost - gather_facts: false - tasks: - - vars: - @{{ data | indent(8) }}@ - @{{ computation | indent(8) }}@ - ansible.builtin.debug: - var: list3 + playbook: ~ .. code-block:: yaml @@ -334,27 +257,7 @@ This produces: .. ansible-output-data:: - env: - ANSIBLE_CALLBACK_RESULT_FORMAT: yaml - variables: - data: - previous_code_block: yaml - previous_code_block_index: 0 - computation: - previous_code_block: yaml+jinja - postprocessors: - - name: reformat-yaml - language: yaml - skip_first_lines: 2 - playbook: |- - - hosts: localhost - gather_facts: false - tasks: - - vars: - @{{ data | indent(8) }}@ - @{{ computation | indent(8) }}@ - ansible.builtin.debug: - var: list3 + playbook: ~ .. code-block:: yaml @@ -392,27 +295,7 @@ This produces: .. ansible-output-data:: - env: - ANSIBLE_CALLBACK_RESULT_FORMAT: yaml - variables: - data: - previous_code_block: yaml - previous_code_block_index: 0 - computation: - previous_code_block: yaml+jinja - postprocessors: - - name: reformat-yaml - language: yaml - skip_first_lines: 2 - playbook: |- - - hosts: localhost - gather_facts: false - tasks: - - vars: - @{{ data | indent(8) }}@ - @{{ computation | indent(8) }}@ - ansible.builtin.debug: - var: list3 + playbook: ~ .. code-block:: yaml @@ -450,27 +333,7 @@ This produces: .. ansible-output-data:: - env: - ANSIBLE_CALLBACK_RESULT_FORMAT: yaml - variables: - data: - previous_code_block: yaml - previous_code_block_index: 0 - computation: - previous_code_block: yaml+jinja - postprocessors: - - name: reformat-yaml - language: yaml - skip_first_lines: 2 - playbook: |- - - hosts: localhost - gather_facts: false - tasks: - - vars: - @{{ data | indent(8) }}@ - @{{ computation | indent(8) }}@ - ansible.builtin.debug: - var: list3 + playbook: ~ .. code-block:: yaml @@ -507,27 +370,7 @@ This produces: .. ansible-output-data:: - env: - ANSIBLE_CALLBACK_RESULT_FORMAT: yaml - variables: - data: - previous_code_block: yaml - previous_code_block_index: 0 - computation: - previous_code_block: yaml+jinja - postprocessors: - - name: reformat-yaml - language: yaml - skip_first_lines: 2 - playbook: |- - - hosts: localhost - gather_facts: false - tasks: - - vars: - @{{ data | indent(8) }}@ - @{{ computation | indent(8) }}@ - ansible.builtin.debug: - var: list3 + playbook: ~ .. code-block:: yaml