ansible.builtin.csvfile (v2.7.18) — lookup

read data from a TSV or CSV file

| "added in version" 1.5 of ansible.builtin"

Authors: Jan-Piet Mens (@jpmens) <jpmens(at)gmail.com>

Install Ansible via pip

Install with pip install ansible==2.7.18

Description

The csvfile lookup reads the contents of a file in CSV (comma-separated value) format. The lookup looks for the row where the first column matches keyname, and returns the value in the second column, unless a different column is specified.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name:  Match 'Li' on the first column, return the second column (0 based index)
  debug: msg="The atomic number of Lithium is {{ lookup('csvfile', 'Li file=elements.csv delimiter=,') }}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: msg="Match 'Li' on the first column, but return the 3rd column (columns start counting after the match)"
  debug: msg="The atomic mass of Lithium is {{ lookup('csvfile', 'Li file=elements.csv delimiter=, col=2') }}"

Inputs

    
col:
    default: '1'
    description: column to return (0 index).

file:
    default: ansible.csv
    description: name of the CSV/TSV file to open.

default:
    default: ''
    description: what to return if the value is not found in the file.

encoding:
    default: utf-8
    description: Encoding (character set) of the used CSV file.
    version_added: '2.1'
    version_added_collection: ansible.builtin

delimiter:
    default: TAB
    description: field separator in the file, for a tab you can specify "TAB" or "t".

Outputs

_raw:
  description:
  - value(s) stored in file column