Skip to content

Commit

Permalink
playbooks_filters: Mention the usage of the ansible.builtin.split fil…
Browse files Browse the repository at this point in the history
…ter (#1929)

* playbooks_filters: Mention the usage of the ansible.builtin.split filter

This is a filter I frequently used in my project, it should mentioned in the documentation so that it can be easily recognized by users.

Fixes #1928.

* Update docs/docsite/rst/playbook_guide/playbooks_filters.rst

Fix inconsistent heading markup style.

Co-authored-by: Felix Fontein <[email protected]>

* playbooks_filters: Fix incorrect _dict_filter label location

Signed-off-by: 林博仁(Buo-ren Lin) <[email protected]>

* playbooks_filters: Fix incorrect argument of the split builtin filter

Signed-off-by: 林博仁(Buo-ren Lin) <[email protected]>

* playbooks_filters: Fix incorrect example input and output

Signed-off-by: 林博仁(Buo-ren Lin) <[email protected]>

* Update docs/docsite/rst/playbook_guide/playbooks_filters.rst

Increase verbosity.

Co-authored-by: Felix Fontein <[email protected]>

---------

Signed-off-by: 林博仁(Buo-ren Lin) <[email protected]>
Co-authored-by: Felix Fontein <[email protected]>
  • Loading branch information
brlin-tw and felixfontein authored Sep 30, 2024
1 parent 99a74bf commit bf81c10
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions docs/docsite/rst/playbook_guide/playbooks_filters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,29 @@ If you are unsure of the underlying Python type of a variable, you can use the :

You should note that, while this may seem like a useful filter for checking that you have the right type of data in a variable, you should often prefer :ref:`type tests <type_tests>`, which will allow you to test for specific data types.

Transforming strings into lists
-------------------------------

Use the :ansplugin:`ansible.builtin.split#filter` filter to transform a character/string delimited string into a list of items suitable for :ref:`looping <playbooks_loops>`. For example, if you want to split a string variable `fruits` by commas, you can use:

.. code-block:: yaml+jinja

{{ fruits | split(',') }}

String data (before applying the :ansplugin:`ansible.builtin.split#filter` filter):

.. code-block:: yaml
fruits: apple,banana,orange
List data (after applying the :ansplugin:`ansible.builtin.split#filter` filter):

.. code-block:: yaml
- apple
- banana
- orange
.. _dict_filter:

Transforming dictionaries into lists
Expand Down

0 comments on commit bf81c10

Please sign in to comment.