From 9410b449e3789cf8dbbba59975fd897d8c5ce13a Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Tue, 1 Oct 2024 08:06:35 +0300 Subject: [PATCH] playbooks_filters: Mention the usage of the ansible.builtin.split filter (#1929) (#1959) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 * playbooks_filters: Fix incorrect _dict_filter label location Signed-off-by: 林博仁(Buo-ren Lin) * playbooks_filters: Fix incorrect argument of the split builtin filter Signed-off-by: 林博仁(Buo-ren Lin) * playbooks_filters: Fix incorrect example input and output Signed-off-by: 林博仁(Buo-ren Lin) * Update docs/docsite/rst/playbook_guide/playbooks_filters.rst Increase verbosity. Co-authored-by: Felix Fontein --------- Signed-off-by: 林博仁(Buo-ren Lin) Co-authored-by: Felix Fontein (cherry picked from commit bf81c101e7efc337bc76e2c3f01842547f4adc2f) Co-authored-by: 林博仁 Buo-ren Lin --- .../rst/playbook_guide/playbooks_filters.rst | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/docsite/rst/playbook_guide/playbooks_filters.rst b/docs/docsite/rst/playbook_guide/playbooks_filters.rst index b9f475a4cd8..bb15adb6f32 100644 --- a/docs/docsite/rst/playbook_guide/playbooks_filters.rst +++ b/docs/docsite/rst/playbook_guide/playbooks_filters.rst @@ -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 `, 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 `. 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