From 8d6e58f2c8c41bc91420bdadcc873b8ac4ef6cad Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Sun, 20 Jul 2025 14:35:59 +0200 Subject: [PATCH] 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: