1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Docs. Remove helpers.

This commit is contained in:
Vladimir Botka 2024-07-16 14:55:13 +02:00
parent 3a24aa5b6d
commit 504749b4e5
No known key found for this signature in database
GPG key ID: 90D199128ED44F01
56 changed files with 0 additions and 1190 deletions

View file

@ -1,61 +0,0 @@
<!--
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
-->
# Docs helper. Create RST file.
The playbook `playbook.yml` writes a RST file that can be used in
docs/docsite/rst. The usage of this helper is recommended but not
mandatory. You can stop reading here and update the RST file manually
if you don't want to use this helper.
## Run the playbook
If you want to generate the RST file by this helper fit the variables
in the playbook and the template to your needs. Then, run the play
```sh
shell> ansible-playbook playbook.yml
```
## Copy RST to docs/docsite/rst
Copy the RST file to `docs/docsite/rst` and remove it from this
directory.
## Update the checksums
Substitute the variables and run the below commands
```sh
shell> sha1sum {{ target_vars }} > {{ target_sha1 }}
shell> sha1sum {{ file_rst }} > {{ file_sha1 }}
```
## Playbook explained
The playbook includes the variable *tests* from the integration tests
and creates the RST file from the template. The playbook will
terminate if:
* The file with the variable *tests* was changed
* The RST file was changed
This means that this helper is probably not up to date.
### The file with the variable *tests* was changed
This means that somebody updated the integration tests. Review the
changes and update the template if needed. Update the checksum to pass
the integrity test. The playbook message provides you with the
command.
### The RST file was changed
This means that somebody updated the RST file manually. Review the
changes and update the template. Update the checksum to pass the
integrity test. The playbook message provides you with the
command. Make sure that the updated template will create identical RST
file. Only then apply your changes.

View file

@ -1,80 +0,0 @@
..
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
keep_keys
"""""""""
Use the filter :ansplugin:`community.general.keep_keys#filter` if you have a list of dictionaries and want to keep certain keys only.
.. 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>`.
Let us use the below list in the following examples:
.. code-block:: yaml
input:
{{ tests.0.input | to_yaml(indent=2) | indent(5) }}
{% for i in tests[0:1]|subelements('group') %}
* {{ i.1.d }}
.. code-block:: yaml+jinja
:emphasize-lines: 1
target: {{ i.1.tt }}
result: "{{ lookup('file', target ~ '/templates/' ~ i.0.template) }}"
{% endfor %}
gives
.. code-block:: yaml
:emphasize-lines: 1-
result:
{{ tests.0.result | to_yaml(indent=2) | indent(5) }}
.. versionadded:: 9.1.0
* The results of the below examples 1-5 are all the same:
.. code-block:: yaml
:emphasize-lines: 1-
result:
{{ tests.1.result | to_yaml(indent=2) | indent(5) }}
{% for i in tests[1:2]|subelements('group') %}
{{ loop.index }}. {{ i.1.d }}
.. code-block:: yaml+jinja
:emphasize-lines: 1,2
mp: {{ i.1.mp }}
target: {{ i.1.tt }}
result: "{{ lookup('file', target ~ '/templates/' ~ i.0.template) }}"
{% endfor %}
* The results of the below examples 6-9 are all the same:
.. code-block:: yaml
:emphasize-lines: 1-
result:
{{ tests.2.result | to_yaml(indent=2) | indent(5) }}
{% for i in tests[2:3]|subelements('group') %}
{{ loop.index + 5 }}. {{ i.1.d }}
.. code-block:: yaml+jinja
:emphasize-lines: 1,2
mp: {{ i.1.mp }}
target: {{ i.1.tt }}
result: "{{ lookup('file', target ~ '/templates/' ~ i.0.template) }}"
{% endfor %}

View file

@ -1 +0,0 @@
8690afce792abc95693c2f61f743ee27388b1592 ../../rst/filter_guide-abstract_informations-lists_of_dictionaries-keep_keys.rst

View file

@ -1,3 +0,0 @@
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

View file

@ -1,79 +0,0 @@
---
# 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
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Create docs REST files
# shell> ansible-playbook playbook.yml
#
# Proofread and copy created *.rst file into the directory
# docs/docsite/rst. Do not add *.rst in this directory to the version
# control.
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# community.general/docs/docsite/helper/keep_keys/playbook.yml
- name: Create RST file for docs/docsite/rst
hosts: localhost
gather_facts: false
vars:
plugin: keep_keys
plugin_type: filter
docs_path:
- filter_guide
- abstract_informations
- lists_of_dictionaries
file_base: "{{ (docs_path + [plugin]) | join('-') }}"
file_rst: ../../rst/{{ file_base }}.rst
file_sha1: "{{ plugin }}.rst.sha1"
target: "../../../../tests/integration/targets/{{ plugin_type }}_{{ plugin }}"
target_vars: "{{ target }}/vars/main/tests.yml"
target_sha1: tests.yml.sha1
tasks:
- name: Test integrity tests.yml
when:
- integrity | d(true) | bool
- lookup('file', target_sha1) != lookup('pipe', 'sha1sum ' ~ target_vars)
block:
- name: Changed tests.yml
ansible.builtin.debug:
msg: |
Changed {{ target_vars }}
Review the changes and update {{ target_sha1 }}
shell> sha1sum {{ target_vars }} > {{ target_sha1 }}
- name: Changed tests.yml end host
ansible.builtin.meta: end_play
- name: Test integrity RST file
when:
- integrity | d(true) | bool
- lookup('file', file_sha1) != lookup('pipe', 'sha1sum ' ~ file_rst)
block:
- name: Changed RST file
ansible.builtin.debug:
msg: |
Changed {{ file_rst }}
Review the changes and update {{ file_sha1 }}
shell> sha1sum {{ file_rst }} > {{ file_sha1 }}
- name: Changed RST file end host
ansible.builtin.meta: end_play
- name: Include target vars
include_vars:
file: "{{ target_vars }}"
- name: Create RST file
ansible.builtin.template:
src: "{{ file_base }}.rst.j2"
dest: "{{ file_base }}.rst"

View file

@ -1 +0,0 @@
c6fc4ee2017d9222675bcd13cc4f88ba8d14f38d ../../../../tests/integration/targets/filter_keep_keys/vars/main/tests.yml

View file

@ -1,3 +0,0 @@
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

View file

@ -1,12 +0,0 @@
---
# 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
list1:
- {name: foo, extra: true}
- {name: bar, extra: false}
- {name: meh, extra: true}
list2:
- {name: foo, path: /foo}
- {name: baz, path: /baz}

View file

@ -1,21 +0,0 @@
---
# 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
list1:
- name: myname01
param01:
x: default_value
y: default_value
list: [default_value]
- name: myname02
param01: [1, 1, 2, 3]
list2:
- name: myname01
param01:
y: patch_value
z: patch_value
list: [patch_value]
- name: myname02
param01: [3, 4, 4]

View file

@ -1,14 +0,0 @@
---
# 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
- name: 1. Merge two lists by common attribute 'name'
include_vars:
dir: example-001_vars
- debug:
var: list3
when: debug | d(false) | bool
- template:
src: list3.out.j2
dest: example-001.out

View file

@ -1 +0,0 @@
../default-common.yml

View file

@ -1,6 +0,0 @@
---
# 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
list3: "{{ list1 |
community.general.lists_mergeby(list2, 'name') }}"

View file

@ -1,14 +0,0 @@
---
# 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
- name: 2. Merge two lists by common attribute 'name'
include_vars:
dir: example-002_vars
- debug:
var: list3
when: debug | d(false) | bool
- template:
src: list3.out.j2
dest: example-002.out

View file

@ -1 +0,0 @@
../default-common.yml

View file

@ -1,6 +0,0 @@
---
# 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
list3: "{{ [list1, list2] |
community.general.lists_mergeby('name') }}"

View file

@ -1,14 +0,0 @@
---
# 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
- name: 3. Merge recursive by 'name', replace lists (default)
include_vars:
dir: example-003_vars
- debug:
var: list3
when: debug | d(false) | bool
- template:
src: list3.out.j2
dest: example-003.out

View file

@ -1 +0,0 @@
../default-recursive-true.yml

View file

@ -1,7 +0,0 @@
---
# 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
list3: "{{ [list1, list2] |
community.general.lists_mergeby('name',
recursive=true) }}"

View file

@ -1,14 +0,0 @@
---
# 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
- name: 4. Merge recursive by 'name', keep lists
include_vars:
dir: example-004_vars
- debug:
var: list3
when: debug | d(false) | bool
- template:
src: list3.out.j2
dest: example-004.out

View file

@ -1 +0,0 @@
../default-recursive-true.yml

View file

@ -1,8 +0,0 @@
---
# 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
list3: "{{ [list1, list2] |
community.general.lists_mergeby('name',
recursive=true,
list_merge='keep') }}"

View file

@ -1,14 +0,0 @@
---
# 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
- name: 5. Merge recursive by 'name', append lists
include_vars:
dir: example-005_vars
- debug:
var: list3
when: debug | d(false) | bool
- template:
src: list3.out.j2
dest: example-005.out

View file

@ -1 +0,0 @@
../default-recursive-true.yml

View file

@ -1,8 +0,0 @@
---
# 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
list3: "{{ [list1, list2] |
community.general.lists_mergeby('name',
recursive=true,
list_merge='append') }}"

View file

@ -1,14 +0,0 @@
---
# 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
- name: 6. Merge recursive by 'name', prepend lists
include_vars:
dir: example-006_vars
- debug:
var: list3
when: debug | d(false) | bool
- template:
src: list3.out.j2
dest: example-006.out

View file

@ -1 +0,0 @@
../default-recursive-true.yml

View file

@ -1,8 +0,0 @@
---
# 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
list3: "{{ [list1, list2] |
community.general.lists_mergeby('name',
recursive=true,
list_merge='prepend') }}"

View file

@ -1,14 +0,0 @@
---
# 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
- name: 7. Merge recursive by 'name', append lists 'remove present'
include_vars:
dir: example-007_vars
- debug:
var: list3
when: debug|d(false) | bool
- template:
src: list3.out.j2
dest: example-007.out

View file

@ -1 +0,0 @@
../default-recursive-true.yml

View file

@ -1,8 +0,0 @@
---
# 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
list3: "{{ [list1, list2] |
community.general.lists_mergeby('name',
recursive=true,
list_merge='append_rp') }}"

View file

@ -1,14 +0,0 @@
---
# 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
- name: 8. Merge recursive by 'name', prepend lists 'remove present'
include_vars:
dir: example-008_vars
- debug:
var: list3
when: debug | d(false) | bool
- template:
src: list3.out.j2
dest: example-008.out

View file

@ -1 +0,0 @@
../default-recursive-true.yml

View file

@ -1,8 +0,0 @@
---
# 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
list3: "{{ [list1, list2] |
community.general.lists_mergeby('name',
recursive=true,
list_merge='prepend_rp') }}"

View file

@ -1,14 +0,0 @@
---
# 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
- name: 9. Merge single list by common attribute 'name'
include_vars:
dir: example-009_vars
- debug:
var: list3
when: debug | d(false) | bool
- template:
src: list3.out.j2
dest: example-009.out

View file

@ -1 +0,0 @@
../default-common.yml

View file

@ -1,6 +0,0 @@
---
# 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
list3: "{{ [list1 + list2, []] |
community.general.lists_mergeby('name') }}"

View file

@ -1,78 +0,0 @@
---
# 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
examples:
- title: Two lists
description: 'In the example below the lists are merged by the attribute ``name``:'
file: example-001_vars/list3.yml
lang: 'yaml+jinja'
- title:
description: 'This produces:'
file: example-001.out
lang: 'yaml'
- title: List of two lists
description: 'It is possible to use a list of lists as an input of the filter:'
file: example-002_vars/list3.yml
lang: 'yaml+jinja'
- title:
description: 'This produces the same result as in the previous example:'
file: example-002.out
lang: 'yaml'
- title: Single list
description: 'It is possible to merge single list:'
file: example-009_vars/list3.yml
lang: 'yaml+jinja'
- title:
description: 'This produces the same result as in the previous example:'
file: example-009.out
lang: 'yaml'
- title: list_merge=replace (default)
description: 'Example :ansopt:`community.general.lists_mergeby#filter:list_merge=replace` (default):'
file: example-003_vars/list3.yml
lang: 'yaml+jinja'
- title:
description: 'This produces:'
file: example-003.out
lang: 'yaml'
- title: list_merge=keep
description: 'Example :ansopt:`community.general.lists_mergeby#filter:list_merge=keep`:'
file: example-004_vars/list3.yml
lang: 'yaml+jinja'
- title:
description: 'This produces:'
file: example-004.out
lang: 'yaml'
- title: list_merge=append
description: 'Example :ansopt:`community.general.lists_mergeby#filter:list_merge=append`:'
file: example-005_vars/list3.yml
lang: 'yaml+jinja'
- title:
description: 'This produces:'
file: example-005.out
lang: 'yaml'
- title: list_merge=prepend
description: 'Example :ansopt:`community.general.lists_mergeby#filter:list_merge=prepend`:'
file: example-006_vars/list3.yml
lang: 'yaml+jinja'
- title:
description: 'This produces:'
file: example-006.out
lang: 'yaml'
- title: list_merge=append_rp
description: 'Example :ansopt:`community.general.lists_mergeby#filter:list_merge=append_rp`:'
file: example-007_vars/list3.yml
lang: 'yaml+jinja'
- title:
description: 'This produces:'
file: example-007.out
lang: 'yaml'
- title: list_merge=prepend_rp
description: 'Example :ansopt:`community.general.lists_mergeby#filter:list_merge=prepend_rp`:'
file: example-008_vars/list3.yml
lang: 'yaml+jinja'
- title:
description: 'This produces:'
file: example-008.out
lang: 'yaml'

View file

@ -1,13 +0,0 @@
..
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
{% for i in examples %}
{{ i.description }}
.. code-block:: {{ i.lang }}
{{ lookup('file', i.file) | split('\n') | reject('match', '^(#|---)') | join ('\n') | indent(2) }}
{% endfor %}

View file

@ -1,7 +0,0 @@
---
# 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
examples_one: true
examples_all: true
merging_lists_of_dictionaries: true

View file

@ -1,74 +0,0 @@
..
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
Merging lists of dictionaries
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
If you have two or more lists of dictionaries and want to combine them into a list of merged dictionaries, where the dictionaries are merged by an attribute, you can use the :ansplugin:`community.general.lists_mergeby <community.general.lists_mergeby#filter>` filter.
.. 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 the documentation for the :ansplugin:`community.general.yaml callback plugin <community.general.yaml#callback>`.
Let us use the lists below in the following examples:
.. code-block:: yaml
{{ lookup('file', 'default-common.yml') | split('\n') | reject('match', '^(#|---)') | join ('\n') | indent(2) }}
{% for i in examples[0:2] %}
{% if i.title | d('', true) | length > 0 %}
{{ i.title }}
{{ "%s" % ('"' * i.title|length) }}
{% endif %}
{{ i.description }}
.. code-block:: {{ i.lang }}
{{ lookup('file', i.file) | split('\n') | reject('match', '^(#|---)') | join ('\n') | indent(2) }}
{% endfor %}
.. versionadded:: 2.0.0
{% for i in examples[2:6] %}
{% if i.title | d('', true) | length > 0 %}
{{ i.title }}
{{ "%s" % ('"' * i.title|length) }}
{% endif %}
{{ i.description }}
.. code-block:: {{ i.lang }}
{{ lookup('file', i.file) | split('\n') | reject('match', '^(#|---)') | join ('\n') | indent(2) }}
{% endfor %}
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.
**recursive**
Is a boolean, default to ``false``. Should the :ansplugin:`community.general.lists_mergeby#filter` filter recursively merge nested hashes. Note: It does not depend on the value of the ``hash_behaviour`` setting in ``ansible.cfg``.
**list_merge**
Is a string, its possible values are :ansval:`replace` (default), :ansval:`keep`, :ansval:`append`, :ansval:`prepend`, :ansval:`append_rp` or :ansval:`prepend_rp`. It modifies the behaviour of :ansplugin:`community.general.lists_mergeby#filter` when the hashes to merge contain arrays/lists.
The examples below set :ansopt:`community.general.lists_mergeby#filter:recursive=true` and display the differences among all six options of :ansopt:`community.general.lists_mergeby#filter:list_merge`. Functionality of the parameters is exactly the same as in the filter :ansplugin:`ansible.builtin.combine#filter`. See :ref:`Combining hashes/dictionaries <combine_filter>` to learn details about these options.
Let us use the lists below in the following examples
.. code-block:: yaml
{{ lookup('file', 'default-recursive-true.yml') | split('\n') | reject('match', '^(#|---)') | join ('\n') |indent(2) }}
{% for i in examples[6:] %}
{% if i.title | d('', true) | length > 0 %}
{{ i.title }}
{{ "%s" % ('"' * i.title|length) }}
{% endif %}
{{ i.description }}
.. code-block:: {{ i.lang }}
{{ lookup('file', i.file) | split('\n') | reject('match', '^(#|---)') | join ('\n') |indent(2) }}
{% endfor %}

View file

@ -1,7 +0,0 @@
{#
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
#}
list3:
{{ list3 | to_yaml(indent=2, sort_keys=false) | indent(2) }}

View file

@ -1,64 +0,0 @@
---
# 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
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# 1) Run all examples and create example-XXX.out
# shell> ansible-playbook playbook.yml -e examples_one=true
#
# 2) Optionally, for testing, create examples_all.rst
# shell> ansible-playbook playbook.yml -e examples_all=true
#
# 3) Create docs REST files
# shell> ansible-playbook playbook.yml -e merging_lists_of_dictionaries=true
#
# Notes:
# * Use YAML callback, e.g. set ANSIBLE_STDOUT_CALLBACK=community.general.yaml
# * Use sphinx-view to render and review the REST files
# shell> sphinx-view <path_to_helper>/examples_all.rst
# * Proofread and copy completed docs *.rst files into the directory rst.
# * Then delete the *.rst and *.out files from this directory. Do not
# add *.rst and *.out in this directory to the version control.
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# community.general/docs/docsite/helper/lists_mergeby/playbook.yml
- hosts: localhost
gather_facts: false
tasks:
- block:
- import_tasks: example-001.yml
tags: t001
- import_tasks: example-002.yml
tags: t002
- import_tasks: example-003.yml
tags: t003
- import_tasks: example-004.yml
tags: t004
- import_tasks: example-005.yml
tags: t005
- import_tasks: example-006.yml
tags: t006
- import_tasks: example-007.yml
tags: t007
- import_tasks: example-008.yml
tags: t008
- import_tasks: example-009.yml
tags: t009
when: examples_one | d(false) | bool
- block:
- include_vars: examples.yml
- template:
src: examples_all.rst.j2
dest: examples_all.rst
when: examples_all | d(false) | bool
- block:
- include_vars: examples.yml
- template:
src: filter_guide_abstract_informations_merging_lists_of_dictionaries.rst.j2
dest: filter_guide_abstract_informations_merging_lists_of_dictionaries.rst
when: merging_lists_of_dictionaries | d(false) | bool

View file

@ -1,61 +0,0 @@
<!--
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
-->
# Docs helper. Create RST file.
The playbook `playbook.yml` writes a RST file that can be used in
docs/docsite/rst. The usage of this helper is recommended but not
mandatory. You can stop reading here and update the RST file manually
if you don't want to use this helper.
## Run the playbook
If you want to generate the RST file by this helper fit the variables
in the playbook and the template to your needs. Then, run the play
```sh
shell> ansible-playbook playbook.yml
```
## Copy RST to docs/docsite/rst
Copy the RST file to `docs/docsite/rst` and remove it from this
directory.
## Update the checksums
Substitute the variables and run the below commands
```sh
shell> sha1sum {{ target_vars }} > {{ target_sha1 }}
shell> sha1sum {{ file_rst }} > {{ file_sha1 }}
```
## Playbook explained
The playbook includes the variable *tests* from the integration tests
and creates the RST file from the template. The playbook will
terminate if:
* The file with the variable *tests* was changed
* The RST file was changed
This means that this helper is probably not up to date.
### The file with the variable *tests* was changed
This means that somebody updated the integration tests. Review the
changes and update the template if needed. Update the checksum to pass
the integrity test. The playbook message provides you with the
command.
### The RST file was changed
This means that somebody updated the RST file manually. Review the
changes and update the template. Update the checksum to pass the
integrity test. The playbook message provides you with the
command. Make sure that the updated template will create identical RST
file. Only then apply your changes.

View file

@ -1,80 +0,0 @@
..
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
remove_keys
"""""""""""
Use the filter :ansplugin:`community.general.remove_keys#filter` if you have a list of dictionaries and want to remove certain keys.
.. 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 See :ansplugin:`the documentation for the community.general.yaml callback plugin <community.general.yaml#callback>`.
Let us use the below list in the following examples:
.. code-block:: yaml
input:
{{ tests.0.input | to_yaml(indent=2) | indent(5) }}
{% for i in tests[0:1]|subelements('group') %}
* {{ i.1.d }}
.. code-block:: yaml+jinja
:emphasize-lines: 1
target: {{ i.1.tt }}
result: "{{ lookup('file', target ~ '/templates/' ~ i.0.template) }}"
{% endfor %}
gives
.. code-block:: yaml
:emphasize-lines: 1-
result:
{{ tests.0.result | to_yaml(indent=2) | indent(5) }}
.. versionadded:: 9.1.0
* The results of the below examples 1-5 are all the same:
.. code-block:: yaml
:emphasize-lines: 1-
result:
{{ tests.1.result | to_yaml(indent=2) | indent(5) }}
{% for i in tests[1:2]|subelements('group') %}
{{ loop.index }}. {{ i.1.d }}
.. code-block:: yaml+jinja
:emphasize-lines: 1,2
mp: {{ i.1.mp }}
target: {{ i.1.tt }}
result: "{{ lookup('file', target ~ '/templates/' ~ i.0.template) }}"
{% endfor %}
* The results of the below examples 6-9 are all the same:
.. code-block:: yaml
:emphasize-lines: 1-
result:
{{ tests.2.result | to_yaml(indent=2) | indent(5) }}
{% for i in tests[2:3]|subelements('group') %}
{{ loop.index + 5 }}. {{ i.1.d }}
.. code-block:: yaml+jinja
:emphasize-lines: 1,2
mp: {{ i.1.mp }}
target: {{ i.1.tt }}
result: "{{ lookup('file', target ~ '/templates/' ~ i.0.template) }}"
{% endfor %}

View file

@ -1,79 +0,0 @@
---
# 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
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Create docs REST files
# shell> ansible-playbook playbook.yml
#
# Proofread and copy created *.rst file into the directory
# docs/docsite/rst. Do not add *.rst in this directory to the version
# control.
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# community.general/docs/docsite/helper/remove_keys/playbook.yml
- name: Create RST file for docs/docsite/rst
hosts: localhost
gather_facts: false
vars:
plugin: remove_keys
plugin_type: filter
docs_path:
- filter_guide
- abstract_informations
- lists_of_dictionaries
file_base: "{{ (docs_path + [plugin]) | join('-') }}"
file_rst: ../../rst/{{ file_base }}.rst
file_sha1: "{{ plugin }}.rst.sha1"
target: "../../../../tests/integration/targets/{{ plugin_type }}_{{ plugin }}"
target_vars: "{{ target }}/vars/main/tests.yml"
target_sha1: tests.yml.sha1
tasks:
- name: Test integrity tests.yml
when:
- integrity | d(true) | bool
- lookup('file', target_sha1) != lookup('pipe', 'sha1sum ' ~ target_vars)
block:
- name: Changed tests.yml
ansible.builtin.debug:
msg: |
Changed {{ target_vars }}
Review the changes and update {{ target_sha1 }}
shell> sha1sum {{ target_vars }} > {{ target_sha1 }}
- name: Changed tests.yml end host
ansible.builtin.meta: end_play
- name: Test integrity RST file
when:
- integrity | d(true) | bool
- lookup('file', file_sha1) != lookup('pipe', 'sha1sum ' ~ file_rst)
block:
- name: Changed RST file
ansible.builtin.debug:
msg: |
Changed {{ file_rst }}
Review the changes and update {{ file_sha1 }}
shell> sha1sum {{ file_rst }} > {{ file_sha1 }}
- name: Changed RST file end host
ansible.builtin.meta: end_play
- name: Include target vars
include_vars:
file: "{{ target_vars }}"
- name: Create RST file
ansible.builtin.template:
src: "{{ file_base }}.rst.j2"
dest: "{{ file_base }}.rst"

View file

@ -1 +0,0 @@
3cc606b42e3d450cf6323f25930f7c5a591fa086 ../../rst/filter_guide-abstract_informations-lists_of_dictionaries-remove_keys.rst

View file

@ -1,3 +0,0 @@
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

View file

@ -1 +0,0 @@
0554335045f02d8c37b824355b0cf86864cee9a5 ../../../../tests/integration/targets/filter_remove_keys/vars/main/tests.yml

View file

@ -1,3 +0,0 @@
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

View file

@ -1,61 +0,0 @@
<!--
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
-->
# Docs helper. Create RST file.
The playbook `playbook.yml` writes a RST file that can be used in
docs/docsite/rst. The usage of this helper is recommended but not
mandatory. You can stop reading here and update the RST file manually
if you don't want to use this helper.
## Run the playbook
If you want to generate the RST file by this helper fit the variables
in the playbook and the template to your needs. Then, run the play
```sh
shell> ansible-playbook playbook.yml
```
## Copy RST to docs/docsite/rst
Copy the RST file to `docs/docsite/rst` and remove it from this
directory.
## Update the checksums
Substitute the variables and run the below commands
```sh
shell> sha1sum {{ target_vars }} > {{ target_sha1 }}
shell> sha1sum {{ file_rst }} > {{ file_sha1 }}
```
## Playbook explained
The playbook includes the variable *tests* from the integration tests
and creates the RST file from the template. The playbook will
terminate if:
* The file with the variable *tests* was changed
* The RST file was changed
This means that this helper is probably not up to date.
### The file with the variable *tests* was changed
This means that somebody updated the integration tests. Review the
changes and update the template if needed. Update the checksum to pass
the integrity test. The playbook message provides you with the
command.
### The RST file was changed
This means that somebody updated the RST file manually. Review the
changes and update the template. Update the checksum to pass the
integrity test. The playbook message provides you with the
command. Make sure that the updated template will create identical RST
file. Only then apply your changes.

View file

@ -1,110 +0,0 @@
..
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
replace_keys
""""""""""""
Use the filter :ansplugin:`community.general.replace_keys#filter` if you have a list of dictionaries and want to replace certain keys.
.. 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>`.
Let us use the below list in the following examples:
.. code-block:: yaml
input:
{{ tests.0.input | to_yaml(indent=2) | indent(5) }}
{% for i in tests[0:1]|subelements('group') %}
* {{ i.1.d }}
.. code-block:: yaml+jinja
:emphasize-lines: 1-3
target:
{{ i.1.tt | to_yaml(indent=2) | indent(5) }}
result: "{{ lookup('file', target ~ '/templates/' ~ i.0.template) }}"
{% endfor %}
gives
.. code-block:: yaml
:emphasize-lines: 1-
result:
{{ tests.0.result | to_yaml(indent=2) | indent(5) }}
.. versionadded:: 9.1.0
* The results of the below examples 1-3 are all the same:
.. code-block:: yaml
:emphasize-lines: 1-
result:
{{ tests.1.result | to_yaml(indent=2) | indent(5) }}
{% for i in tests[1:2]|subelements('group') %}
{{ loop.index }}. {{ i.1.d }}
.. code-block:: yaml+jinja
:emphasize-lines: 1-4
mp: {{ i.1.mp }}
target:
{{ i.1.tt | to_yaml(indent=2) | indent(5) }}
result: "{{ lookup('file', target ~ '/templates/' ~ i.0.template) }}"
{% endfor %}
* The results of the below examples 4-5 are the same:
.. code-block:: yaml
:emphasize-lines: 1-
result:
{{ tests.2.result | to_yaml(indent=2) | indent(5) }}
{% for i in tests[2:3]|subelements('group') %}
{{ loop.index + 3 }}. {{ i.1.d }}
.. code-block:: yaml+jinja
:emphasize-lines: 1-3
mp: {{ i.1.mp }}
target:
{{ i.1.tt | to_yaml(indent=2) | indent(5) }}
result: "{{ lookup('file', target ~ '/templates/' ~ i.0.template) }}"
{% endfor %}
{% for i in tests[3:4]|subelements('group') %}
{{ loop.index + 5 }}. {{ i.1.d }}
.. code-block:: yaml
:emphasize-lines: 1-
input:
{{ i.0.input | to_yaml(indent=2) | indent(5) }}
.. code-block:: yaml+jinja
:emphasize-lines: 1-4
mp: {{ i.1.mp }}
target:
{{ i.1.tt | to_yaml(indent=2) | indent(5) }}
result: "{{ lookup('file', target ~ '/templates/' ~ i.0.template) }}"
gives
.. code-block:: yaml
:emphasize-lines: 1-
result:
{{ i.0.result | to_yaml(indent=2) | indent(5) }}
{% endfor %}

View file

@ -1,79 +0,0 @@
---
# 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
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Create docs REST files
# shell> ansible-playbook playbook.yml
#
# Proofread and copy created *.rst file into the directory
# docs/docsite/rst. Do not add *.rst in this directory to the version
# control.
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# community.general/docs/docsite/helper/replace_keys/playbook.yml
- name: Create RST file for docs/docsite/rst
hosts: localhost
gather_facts: false
vars:
plugin: replace_keys
plugin_type: filter
docs_path:
- filter_guide
- abstract_informations
- lists_of_dictionaries
file_base: "{{ (docs_path + [plugin]) | join('-') }}"
file_rst: ../../rst/{{ file_base }}.rst
file_sha1: "{{ plugin }}.rst.sha1"
target: "../../../../tests/integration/targets/{{ plugin_type }}_{{ plugin }}"
target_vars: "{{ target }}/vars/main/tests.yml"
target_sha1: tests.yml.sha1
tasks:
- name: Test integrity tests.yml
when:
- integrity | d(true) | bool
- lookup('file', target_sha1) != lookup('pipe', 'sha1sum ' ~ target_vars)
block:
- name: Changed tests.yml
ansible.builtin.debug:
msg: |
Changed {{ target_vars }}
Review the changes and update {{ target_sha1 }}
shell> sha1sum {{ target_vars }} > {{ target_sha1 }}
- name: Changed tests.yml end host
ansible.builtin.meta: end_play
- name: Test integrity RST file
when:
- integrity | d(true) | bool
- lookup('file', file_sha1) != lookup('pipe', 'sha1sum ' ~ file_rst)
block:
- name: Changed RST file
ansible.builtin.debug:
msg: |
Changed {{ file_rst }}
Review the changes and update {{ file_sha1 }}
shell> sha1sum {{ file_rst }} > {{ file_sha1 }}
- name: Changed RST file end host
ansible.builtin.meta: end_play
- name: Include target vars
include_vars:
file: "{{ target_vars }}"
- name: Create RST file
ansible.builtin.template:
src: "{{ file_base }}.rst.j2"
dest: "{{ file_base }}.rst"

View file

@ -1 +0,0 @@
403f23c02ac02b1c3b611cb14f9b3ba59dc3f587 ../../rst/filter_guide-abstract_informations-lists_of_dictionaries-replace_keys.rst

View file

@ -1,3 +0,0 @@
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

View file

@ -1 +0,0 @@
2e54f3528c95cca746d5748f1ed7ada56ad0890e ../../../../tests/integration/targets/filter_replace_keys/vars/main/tests.yml

View file

@ -1,3 +0,0 @@
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