community.general.from_csv (8.5.0) — filter

Converts CSV text input into list of dicts

| "added in version" 2.3.0 of community.general"

Authors: Andrew Pantuso (@Ajpantuso)

Install collection

Install with ansible-galaxy collection install community.general:==8.5.0


Add to requirements.yml

  collections:
    - name: community.general
      version: 8.5.0

Description

Converts CSV text input into list of dictionaries.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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

Inputs

    
_input:
    description: A string containing a CSV document.
    required: true
    type: string

strict:
    description:
    - Whether to raise an exception on bad CSV input.
    - When using this parameter, you change the default value used by O(dialect).
    - The default value depends on the dialect used.
    type: bool

dialect:
    default: excel
    description:
    - The CSV dialect to use when parsing the CSV file.
    - Possible values include V(excel), V(excel-tab) or V(unix).
    type: str

delimiter:
    description:
    - A one-character string used to separate fields.
    - When using this parameter, you change the default value used by O(dialect).
    - The default value depends on the dialect used.
    type: str

fieldnames:
    description:
    - A list of field names for every column.
    - This is needed if the CSV does not have a header.
    elements: str
    type: list

skipinitialspace:
    description:
    - Whether to ignore any whitespaces immediately following the delimiter.
    - When using this parameter, you change the default value used by O(dialect).
    - The default value depends on the dialect used.
    type: bool

Outputs

_value:
  description: A list with one dictionary per row.
  elements: dictionary
  type: list