community.general.from_csv filter – Converts CSV text input into list of dicts
Note
This filter plugin is part of the community.general collection (version 9.4.0).
It is not included in ansible-core
.
To check whether it is installed, run ansible-galaxy collection list
.
To install it, use: ansible-galaxy collection install community.general
.
To use it in a playbook, specify: community.general.from_csv
.
New in community.general 2.3.0
Synopsis
Converts CSV text input into list of dictionaries.
Input
This describes the input of the filter, the value before | community.general.from_csv
.
Parameter |
Comments |
---|---|
A string containing a CSV document. |
Keyword parameters
This describes keyword parameters of the filter. These are the values key1=value1
, key2=value2
and so on in the following
example: input | community.general.from_csv(key1=value1, key2=value2, ...)
Parameter |
Comments |
---|---|
A one-character string used to separate fields. When using this parameter, you change the default value used by The default value depends on the dialect used. |
|
The CSV dialect to use when parsing the CSV file. Possible values include Default: |
|
A list of field names for every column. This is needed if the CSV does not have a header. |
|
Whether to ignore any whitespaces immediately following the delimiter. When using this parameter, you change the default value used by The default value depends on the dialect used. Choices:
|
|
Whether to raise an exception on bad CSV input. When using this parameter, you change the default value used by The default value depends on the dialect used. Choices:
|
Examples
- name: Parse a CSV file's contents
ansible.builtin.debug:
msg: >-
{{ csv_data | community.general.from_csv(dialect='unix') }}
vars:
csv_data: |
Column 1,Value
foo,23
bar,42
# Produces the following list of dictionaries:
# {
# "Column 1": "foo",
# "Value": "23",
# },
# {
# "Column 1": "bar",
# "Value": "42",
# }
Return Value
Key |
Description |
---|---|
A list with one dictionary per row. Returned: success |