Skip to content

Commit 80456f7

Browse files
playbooks_filters: Mention the usage of the ansible.builtin.split filter (#1929) (#1958)
* 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]> (cherry picked from commit bf81c10) Co-authored-by: 林博仁 Buo-ren Lin <[email protected]>
1 parent 133abd1 commit 80456f7

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

docs/docsite/rst/playbook_guide/playbooks_filters.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,29 @@ If you are unsure of the underlying Python type of a variable, you can use the :
116116

117117
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.
118118

119+
Transforming strings into lists
120+
-------------------------------
121+
122+
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:
123+
124+
.. code-block:: yaml+jinja
125+
126+
{{ fruits | split(',') }}
127+
128+
String data (before applying the :ansplugin:`ansible.builtin.split#filter` filter):
129+
130+
.. code-block:: yaml
131+
132+
fruits: apple,banana,orange
133+
134+
List data (after applying the :ansplugin:`ansible.builtin.split#filter` filter):
135+
136+
.. code-block:: yaml
137+
138+
- apple
139+
- banana
140+
- orange
141+
119142
.. _dict_filter:
120143

121144
Transforming dictionaries into lists

0 commit comments

Comments
 (0)